update forgetPassword route url

This commit is contained in:
秦秋旭 2023-02-24 00:28:58 +08:00
parent 03ad1187ce
commit 56ae208717
3 changed files with 8 additions and 8 deletions

View File

@ -5,4 +5,7 @@ export class ResetPassword extends EmailVerifyDto {
@IsNotEmpty() @IsNotEmpty()
@IsStrongPassword() @IsStrongPassword()
password: string password: string
@IsNotEmpty()
userId: string
} }

View File

@ -23,12 +23,9 @@ export class UsersController {
return this.usersService.loginByEmail(user.email, user.password) return this.usersService.loginByEmail(user.email, user.password)
} }
@Patch(':id/password') @Patch('password')
@ApiOperation({ summary: '找回密码' }) @ApiOperation({ summary: '找回密码' })
async forgetPassword( async forgetPassword(@Body() payload: ResetPassword) {
@Body() payload: ResetPassword, return this.usersService.resetPasswordByEmail(payload)
@Param('id') userId: string,
) {
return this.usersService.resetPasswordByEmail(payload, userId)
} }
} }

View File

@ -47,14 +47,14 @@ export class UsersService {
} }
@VerifyEmail(EmailScene.forgetPassword) @VerifyEmail(EmailScene.forgetPassword)
async resetPasswordByEmail(data: ResetPassword, userId: string) { async resetPasswordByEmail(data: ResetPassword) {
const { password } = data const { password } = data
const hashedPassword = await bcrypt.hash( const hashedPassword = await bcrypt.hash(
password, password,
this.secureConfig.bcryptSaltOrRound, this.secureConfig.bcryptSaltOrRound,
) )
const user = await this.prismaService.user.update({ const user = await this.prismaService.user.update({
where: { id: userId }, where: { id: data.userId },
data: { password: hashedPassword }, data: { password: hashedPassword },
}) })
return this.generateTokens({ userId: user.id }) return this.generateTokens({ userId: user.id })