Merge pull request #121 from SyncrowIOT/forgot-password-fix

Forgot password fix
This commit is contained in:
yousef-khriasat-uba
2024-10-21 14:23:00 +03:00
committed by GitHub
3 changed files with 25 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import {
BadRequestException,
Body,
Controller,
Get,
@ -16,6 +17,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,12 +76,24 @@ export class UserAuthController {
@Post('user/forget-password')
async forgetPassword(@Body() forgetPasswordDto: ForgetPasswordDto) {
await this.userAuthService.forgetPassword(forgetPasswordDto);
return {
statusCode: HttpStatus.OK,
data: {},
message: 'Password changed successfully',
};
const otpResult = await this.userAuthService.verifyOTP({
otpCode: forgetPasswordDto.otpCode,
email: forgetPasswordDto.email,
type: OtpType.PASSWORD,
});
if (otpResult) {
await this.userAuthService.forgetPassword(forgetPasswordDto);
return {
statusCode: HttpStatus.OK,
data: {},
message: 'Password changed successfully',
};
}
throw new BadRequestException({
statusCode: HttpStatus.BAD_REQUEST,
data: {},
message: 'Otp is incorrect',
})
}
@ApiBearerAuth()

View File

@ -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;
}

View File

@ -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 {