feat(login): 二级密码登录支持(STATUS_SECONDARY_PASSCODE_ERROR #1)
Some checks failed
CI / Lint (push) Has been cancelled
Some checks failed
CI / Lint (push) Has been cancelled
## 问题 旧版 Flutter 项目在 /vcode/check 返回 30164 时展示二级密码输入界面; 新版完全缺失此路径,有二级密码的账号无法登录。 ## 改动 ### networks_sdk - `networks_sdk_method_channel_datasource.dart`:executeRequest 的 generic catch 改为 rethrow,允许 decodeResponse override 抛出 自定义业务异常(原为 ApiError.unknown 包裹导致数据丢失) ### 数据层 - `errors.dart`:新增 `secondaryPasscodeRequired = 30164` - `exceptions.dart`(新增):`SecondaryPasscodeRequiredException` 携带 vcodeToken / recoveryEmail / hint / resetStatus - `verify_otp_request.dart`:override decodeResponse,拦截 30164, 从响应 data 提取字段,throw SecondaryPasscodeRequiredException - `login_request.dart`:新增可选 password 字段 + toJson override (条件序列化,null 时不带 password 字段) - `auth_repository.dart`:新增 loginWithPasscode() 接口 - `auth_repository_impl.dart`:实现 loginWithPasscode() ### 业务层 - `login_usecase.dart`:新增 loginWithSecondaryPasscode() (MD5 哈希 passcode → 调 AuthRepository.loginWithPasscode) - `pubspec.yaml`:新增 crypto: ^3.0.6(用于 MD5) ### UI 层 - `login_state.dart`:新增 LoginStep.secondaryPasscode + vcodeToken / passcodeHint / recoveryEmail 字段 - `login_view_model.dart`:verifyAndLogin 捕获 SecondaryPasscodeRequiredException 跳转步骤 3;新增 verifyPasscode() - `login_secondary_passcode_step.dart`(新增):密码输入 UI(hint 显示、 obscured 输入框、错误提示、忘记密码占位) - `login_page.dart`:switch 路由接入 LoginStep.secondaryPasscode
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:networks_sdk/networks_sdk.dart';
|
||||
import 'package:storage_sdk/storage_sdk.dart';
|
||||
|
||||
@@ -115,6 +118,48 @@ class LoginUseCase {
|
||||
return user;
|
||||
}
|
||||
|
||||
/// 步骤 2b:用户输入二级密码后完成登录
|
||||
///
|
||||
/// 在 [verifyAndLogin] 抛出 [SecondaryPasscodeRequiredException] 后调用:
|
||||
/// - MD5 哈希用户输入的密码
|
||||
/// - 调 [AuthRepository.loginWithPasscode]
|
||||
/// - 初始化 WebSocket / 数据库(与 [verifyAndLogin] 后半段一致)
|
||||
///
|
||||
/// 抛出:
|
||||
/// - [FormatException] — 密码为空
|
||||
/// - [ApiError] — 网络/服务端错误(密码错误 → 服务端返回错误码)
|
||||
Future<User> loginWithSecondaryPasscode({
|
||||
required String countryCode,
|
||||
required String contact,
|
||||
required String vcodeToken,
|
||||
required String passcode,
|
||||
}) async {
|
||||
if (passcode.trim().isEmpty) {
|
||||
throw const FormatException('密码不能为空');
|
||||
}
|
||||
|
||||
// MD5 哈希(对齐旧版 makeMD5 逻辑)
|
||||
final bytes = utf8.encode(passcode);
|
||||
final passwordMd5 = md5.convert(bytes).toString();
|
||||
|
||||
final user = await _authRepository.loginWithPasscode(
|
||||
countryCode: countryCode,
|
||||
contact: contact,
|
||||
vcodeToken: vcodeToken,
|
||||
passwordMd5: passwordMd5,
|
||||
);
|
||||
|
||||
final token = _apiConfig.token;
|
||||
if (token != null && token.isNotEmpty) {
|
||||
await _socketManager.connect(token: token);
|
||||
}
|
||||
|
||||
await _storageLifeCycle.openDatabase(user.uid);
|
||||
await _userRepository.insertOrReplaceUser(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
void _validatePhone(String contact) {
|
||||
final trimmed = contact.trim();
|
||||
if (trimmed.isEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user