From fa4a31a6ffa64de6ef28b739c37ac1fff8a9e18f Mon Sep 17 00:00:00 2001 From: tone Date: Thu, 18 Dec 2025 17:08:23 +0800 Subject: [PATCH] =?UTF-8?q?secure:=20=E8=B0=83=E6=95=B4=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E7=9A=84=E5=93=8D=E5=BA=94=E4=B8=BAnull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/src/user/user.controller.ts | 5 +++-- apps/backend/src/user/user.service.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/backend/src/user/user.controller.ts b/apps/backend/src/user/user.controller.ts index f4a49a5..bf8b791 100644 --- a/apps/backend/src/user/user.controller.ts +++ b/apps/backend/src/user/user.controller.ts @@ -18,7 +18,8 @@ export class UserController { @UseGuards(AuthGuard) @Put('password') - async update(@CurrentUser() user: AuthUser, @Body() dto: UpdateUserPasswordDto) { - return this.userService.setPassword(user.userId, dto.password); + async update(@CurrentUser() user: AuthUser, @Body() dto: UpdateUserPasswordDto): Promise { + await this.userService.setPassword(user.userId, dto.password.trim()); + return null; } } diff --git a/apps/backend/src/user/user.service.ts b/apps/backend/src/user/user.service.ts index 950adec..a10fe7b 100644 --- a/apps/backend/src/user/user.service.ts +++ b/apps/backend/src/user/user.service.ts @@ -133,15 +133,15 @@ export class UserService { return uuid().replace(/-/g, ''); } - async setPassword(userId: string, password: string): Promise { + async setPassword(userId: string, password: string) { const user = await this.userRepository.findOne({ where: { userId } }); if (!user) { - throw new BadRequestException('User not found'); + throw new BadRequestException('用户不存在'); } const salt = this.generateSalt(); user.password_hash = this.hashPassword(password, salt); user.salt = salt; - return this.userRepository.save(user); + await this.userRepository.save(user); } private getDuplicateErrorMessage(error: QueryFailedError): string {