Loading backend/src/auth/user/authUsercontroller.ts +22 −2 Original line number Diff line number Diff line import { Body, Controller, Patch, Post, Req, UseGuards } from '@nestjs/common'; import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common'; import { ApiBearerAuth, ApiBody, ApiCreatedResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; import { AuthUserService } from './authUserservice'; import { CreateUserDto } from 'src/user/dto/create-user.dto'; Loading @@ -7,11 +7,14 @@ import { UserSigninResDto } from './dto/user-signin-res.dto'; import { AuthUserGuard } from './authUser.guard'; import { CustomUserRequest } from './interface/customUserReq'; import { UpdatePwdDto } from './dto/update-pwd.dto'; import { UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto } from './dto/user-reset-password.dto'; import { GetResetCode } from './dto/get-reset-code.dto'; import { EmailService } from 'src/email/email.service'; @Controller('') @ApiTags('Create user account and sign in as user') export class AuthUserController { constructor(private readonly authUserService: AuthUserService) {} constructor(private readonly authUserService: AuthUserService, private readonly mailService: EmailService) {} @ApiBody({ type: CreateUserDto }) @ApiCreatedResponse({ Loading Loading @@ -47,4 +50,21 @@ export class AuthUserController { async changePassword(@Req() req: CustomUserRequest, @Body() updatePwdDto: UpdatePwdDto) { return this.authUserService.changePassword(req.user.email, updatePwdDto); } @ApiBody({ type: UserResetPasswordBody }) @Post('user/reset-password') async resetPassword(@Body() resetPasswordDto: UserResetPasswordDto) { return this.authUserService.resetPassword(resetPasswordDto); } @ApiBody({ type: UserRequestCodeBody }) @Post('user/get-reset-code') async getResetCode(@Body() resetPasswordInfo: GetResetCode) { try{ const code = await this.authUserService.getResetPasswordCode(resetPasswordInfo.email); await this.mailService.sendResetPasswordEmail(resetPasswordInfo.email, code); } catch (e) { throw e; } } } Loading
backend/src/auth/user/authUsercontroller.ts +22 −2 Original line number Diff line number Diff line import { Body, Controller, Patch, Post, Req, UseGuards } from '@nestjs/common'; import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common'; import { ApiBearerAuth, ApiBody, ApiCreatedResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; import { AuthUserService } from './authUserservice'; import { CreateUserDto } from 'src/user/dto/create-user.dto'; Loading @@ -7,11 +7,14 @@ import { UserSigninResDto } from './dto/user-signin-res.dto'; import { AuthUserGuard } from './authUser.guard'; import { CustomUserRequest } from './interface/customUserReq'; import { UpdatePwdDto } from './dto/update-pwd.dto'; import { UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto } from './dto/user-reset-password.dto'; import { GetResetCode } from './dto/get-reset-code.dto'; import { EmailService } from 'src/email/email.service'; @Controller('') @ApiTags('Create user account and sign in as user') export class AuthUserController { constructor(private readonly authUserService: AuthUserService) {} constructor(private readonly authUserService: AuthUserService, private readonly mailService: EmailService) {} @ApiBody({ type: CreateUserDto }) @ApiCreatedResponse({ Loading Loading @@ -47,4 +50,21 @@ export class AuthUserController { async changePassword(@Req() req: CustomUserRequest, @Body() updatePwdDto: UpdatePwdDto) { return this.authUserService.changePassword(req.user.email, updatePwdDto); } @ApiBody({ type: UserResetPasswordBody }) @Post('user/reset-password') async resetPassword(@Body() resetPasswordDto: UserResetPasswordDto) { return this.authUserService.resetPassword(resetPasswordDto); } @ApiBody({ type: UserRequestCodeBody }) @Post('user/get-reset-code') async getResetCode(@Body() resetPasswordInfo: GetResetCode) { try{ const code = await this.authUserService.getResetPasswordCode(resetPasswordInfo.email); await this.mailService.sendResetPasswordEmail(resetPasswordInfo.email, code); } catch (e) { throw e; } } }