From f165e8ce3a029daabb5aebf287458bf8751a76d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Oct 2024 14:18:31 +0300 Subject: [PATCH] fixed forgot password --- src/auth/controllers/user-auth.controller.ts | 6 ++++++ src/auth/dtos/user-password.dto.ts | 5 +++++ src/auth/services/user-auth.service.ts | 1 - 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/auth/controllers/user-auth.controller.ts b/src/auth/controllers/user-auth.controller.ts index bc9fc3c..1bf429b 100644 --- a/src/auth/controllers/user-auth.controller.ts +++ b/src/auth/controllers/user-auth.controller.ts @@ -16,6 +16,7 @@ import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos'; import { RefreshTokenGuard } from '@app/common/guards/jwt-refresh.auth.guard'; import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard'; import { EnableDisableStatusEnum } from '@app/common/constants/days.enum'; +import { OtpType } from '@app/common/constants/otp-type.enum'; @Controller({ version: EnableDisableStatusEnum.ENABLED, @@ -74,6 +75,11 @@ export class UserAuthController { @Post('user/forget-password') async forgetPassword(@Body() forgetPasswordDto: ForgetPasswordDto) { + await this.userAuthService.verifyOTP({ + otpCode: forgetPasswordDto.otpCode, + email: forgetPasswordDto.email, + type: OtpType.PASSWORD, + }); await this.userAuthService.forgetPassword(forgetPasswordDto); return { statusCode: HttpStatus.OK, diff --git a/src/auth/dtos/user-password.dto.ts b/src/auth/dtos/user-password.dto.ts index 9a93935..de5eb5b 100644 --- a/src/auth/dtos/user-password.dto.ts +++ b/src/auth/dtos/user-password.dto.ts @@ -22,4 +22,9 @@ export class ForgetPasswordDto { 'password must be at least 8 characters long and include at least one uppercase letter, one lowercase letter, one numeric digit, and one special character.', }) public password: string; + + @ApiProperty() + @IsString() + @IsNotEmpty() + public otpCode: string; } diff --git a/src/auth/services/user-auth.service.ts b/src/auth/services/user-auth.service.ts index 9fd9fe3..c924658 100644 --- a/src/auth/services/user-auth.service.ts +++ b/src/auth/services/user-auth.service.ts @@ -18,7 +18,6 @@ import * as argon2 from 'argon2'; import { differenceInSeconds } from '@app/common/helper/differenceInSeconds'; import { LessThan, MoreThan } from 'typeorm'; import { ConfigService } from '@nestjs/config'; -import { UUID } from 'typeorm/driver/mongodb/bson.typings'; @Injectable() export class UserAuthService {