fix(password): 统一登录密码和支付密码状态查询为服务端 API
问题:
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
728b11c2aa
commit
a1d284b6b5
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -2861,6 +2861,14 @@ export class UserApplicationService {
|
|||
/**
|
||||
* 查询是否已设置支付密码
|
||||
*/
|
||||
async isLoginPasswordSet(userId: string): Promise<boolean> {
|
||||
const user = await this.prisma.userAccount.findUnique({
|
||||
where: { userId: BigInt(userId) },
|
||||
select: { passwordHash: true },
|
||||
});
|
||||
return !!user?.passwordHash;
|
||||
}
|
||||
|
||||
async isPaymentPasswordSet(userId: string): Promise<boolean> {
|
||||
const user = await this.prisma.userAccount.findUnique({
|
||||
where: { userId: BigInt(userId) },
|
||||
|
|
|
|||
|
|
@ -2059,11 +2059,16 @@ class AccountService {
|
|||
|
||||
/// 检查是否已设置密码
|
||||
Future<bool> isPasswordSet() async {
|
||||
debugPrint('$_tag isPasswordSet() - 检查是否已设置密码');
|
||||
final isSet = await _secureStorage.read(key: StorageKeys.isPasswordSet);
|
||||
final result = isSet == 'true';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// 修改登录密码
|
||||
|
|
|
|||
Loading…
Reference in New Issue