From d16cd9bc66d4f27d0aae4f84420560606e1bab90 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 10 Mar 2026 20:45:52 -0700 Subject: [PATCH] =?UTF-8?q?fix(auth-service):=20=E8=A1=A5=E5=85=A8=20Reset?= =?UTF-8?q?PasswordDto/ChangePasswordDto=20=E7=9A=84=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E8=A3=85=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ValidationPipe 的 forbidNonWhitelisted 因缺少 class-validator 装饰器 将重置密码请求全部拒绝(400 Bad Request),导致找回密码流程无法完成。 Co-Authored-By: Claude Sonnet 4.6 --- .../src/api/controllers/password.controller.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/services/auth-service/src/api/controllers/password.controller.ts b/backend/services/auth-service/src/api/controllers/password.controller.ts index b20367a5..3421ed5b 100644 --- a/backend/services/auth-service/src/api/controllers/password.controller.ts +++ b/backend/services/auth-service/src/api/controllers/password.controller.ts @@ -7,6 +7,7 @@ import { UseGuards, } from '@nestjs/common'; import { ThrottlerGuard } from '@nestjs/throttler'; +import { IsString, IsNotEmpty, Matches, MinLength } from 'class-validator'; import { PasswordService } from '@/application/services'; import { JwtAuthGuard } from '@/shared/guards/jwt-auth.guard'; import { CapabilityGuard } from '@/shared/guards/capability.guard'; @@ -14,13 +15,30 @@ import { CurrentUser } from '@/shared/decorators/current-user.decorator'; import { RequireCapability } from '@/shared/decorators/require-capability.decorator'; class ResetPasswordDto { + @IsString() + @IsNotEmpty() + @Matches(/^1[3-9]\d{9}$/, { message: '手机号格式不正确' }) phone: string; + + @IsString() + @IsNotEmpty() + @Matches(/^\d{6}$/, { message: '验证码格式不正确' }) smsCode: string; + + @IsString() + @IsNotEmpty() + @MinLength(6, { message: '密码至少6位' }) newPassword: string; } class ChangePasswordDto { + @IsString() + @IsNotEmpty() oldPassword: string; + + @IsString() + @IsNotEmpty() + @MinLength(6, { message: '密码至少6位' }) newPassword: string; }