From a1d284b6b5e75841027ab026f558c13c444fe23f Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 5 Mar 2026 08:14:24 -0800 Subject: [PATCH] =?UTF-8?q?fix(password):=20=E7=BB=9F=E4=B8=80=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=AF=86=E7=A0=81=E5=92=8C=E6=94=AF=E4=BB=98=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2=E4=B8=BA=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - isPasswordSet() 读 SecureStorage,重装/换设备后丢失 → 页面误判未设密码 - isPaymentPasswordSet() 读 response.data['isSet'],但实际格式为 { success, data: { isSet } },取到 null → 始终返回 false 修复: - 后端新增 GET /user/password-status 接口(isLoginPasswordSet 方法) - 前端 isPasswordSet() 改为调用服务端 API - 两个方法均使用正确的 response.data['data']['isSet'] 解包 Co-Authored-By: Claude Sonnet 4.6 --- .../api/controllers/user-account.controller.ts | 11 +++++++++++ .../services/user-application.service.ts | 8 ++++++++ .../lib/core/services/account_service.dart | 15 ++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/backend/services/identity-service/src/api/controllers/user-account.controller.ts b/backend/services/identity-service/src/api/controllers/user-account.controller.ts index 688576f2..1b4a72c8 100644 --- a/backend/services/identity-service/src/api/controllers/user-account.controller.ts +++ b/backend/services/identity-service/src/api/controllers/user-account.controller.ts @@ -756,6 +756,17 @@ export class UserAccountController { return { valid }; } + // ============ 密码状态查询 ============ + + @Get('password-status') + @ApiBearerAuth() + @ApiOperation({ summary: '查询登录密码状态', description: '查询当前用户是否已设置登录密码' }) + @ApiResponse({ status: 200, description: '{ isSet: boolean }' }) + async getPasswordStatus(@CurrentUser() user: CurrentUserData) { + const isSet = await this.userService.isLoginPasswordSet(user.userId); + return { isSet }; + } + // ============ 支付密码相关 ============ @Get('payment-password-status') diff --git a/backend/services/identity-service/src/application/services/user-application.service.ts b/backend/services/identity-service/src/application/services/user-application.service.ts index c15e4c4d..0b5ca08c 100644 --- a/backend/services/identity-service/src/application/services/user-application.service.ts +++ b/backend/services/identity-service/src/application/services/user-application.service.ts @@ -2861,6 +2861,14 @@ export class UserApplicationService { /** * 查询是否已设置支付密码 */ + async isLoginPasswordSet(userId: string): Promise { + const user = await this.prisma.userAccount.findUnique({ + where: { userId: BigInt(userId) }, + select: { passwordHash: true }, + }); + return !!user?.passwordHash; + } + async isPaymentPasswordSet(userId: string): Promise { const user = await this.prisma.userAccount.findUnique({ where: { userId: BigInt(userId) }, diff --git a/frontend/mobile-app/lib/core/services/account_service.dart b/frontend/mobile-app/lib/core/services/account_service.dart index 4e87d8e2..ae370f1d 100644 --- a/frontend/mobile-app/lib/core/services/account_service.dart +++ b/frontend/mobile-app/lib/core/services/account_service.dart @@ -2059,11 +2059,16 @@ class AccountService { /// 检查是否已设置密码 Future isPasswordSet() async { - debugPrint('$_tag isPasswordSet() - 检查是否已设置密码'); - final isSet = await _secureStorage.read(key: StorageKeys.isPasswordSet); - final result = isSet == 'true'; - debugPrint('$_tag isPasswordSet() - 结果: $result'); - return result; + debugPrint('$_tag isPasswordSet() - 查询登录密码状态'); + try { + final response = await _apiClient.get('/user/password-status'); + final result = response.data['data']['isSet'] == true; + debugPrint('$_tag isPasswordSet() - 结果: $result'); + return result; + } catch (e) { + debugPrint('$_tag isPasswordSet() - 异常: $e'); + rethrow; + } } /// 修改登录密码