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; + } } /// 修改登录密码