feat(auth): 对接后端 open 模块认证接口并完善登录页
- 更新接口路径、字段和短信验证码场景,新增忘记密码/重置密码流程 - 增加 401 自动刷新 token 与统一错误处理 - 重构登录页 UI,支持退出确认、协议与法律文档入口
This commit is contained in:
@@ -6,7 +6,9 @@ import '../domain/auth_repository.dart';
|
||||
|
||||
/// 认证仓库实现(数据层)。
|
||||
///
|
||||
/// 通过 DioClient 调用后台,将 JSON DTO 映射为领域实体,并持久化令牌。
|
||||
/// 对接后端 C 端(open 模块)认证接口,全部端点以 `/api/v1/open/auth/**` 为前缀
|
||||
/// (`AppConstants.kBaseUrl` 已包含该前缀)。open 模块账号落地 `app_user`,
|
||||
/// 与后台管理端(`sys_user`)物理分表,令牌经 `TokenManager.generateToken` 本地签发。
|
||||
class AuthRepositoryImpl implements AuthRepository {
|
||||
const AuthRepositoryImpl();
|
||||
|
||||
@@ -17,12 +19,10 @@ class AuthRepositoryImpl implements AuthRepository {
|
||||
required String deviceId,
|
||||
}) async {
|
||||
final data = await DioClient.post(
|
||||
'/auth/login',
|
||||
'/login',
|
||||
data: {
|
||||
'phone': phone,
|
||||
'username': phone,
|
||||
'password': password,
|
||||
'deviceId': deviceId,
|
||||
'type': 'password',
|
||||
},
|
||||
);
|
||||
final result = LoginResult.fromJson(data as Map<String, dynamic>);
|
||||
@@ -40,12 +40,10 @@ class AuthRepositoryImpl implements AuthRepository {
|
||||
required String deviceId,
|
||||
}) async {
|
||||
final data = await DioClient.post(
|
||||
'/auth/login',
|
||||
'auth/login/mobile',
|
||||
data: {
|
||||
'phone': phone,
|
||||
'mobile': phone,
|
||||
'code': code,
|
||||
'deviceId': deviceId,
|
||||
'type': 'sms',
|
||||
},
|
||||
);
|
||||
final result = LoginResult.fromJson(data as Map<String, dynamic>);
|
||||
@@ -64,12 +62,11 @@ class AuthRepositoryImpl implements AuthRepository {
|
||||
required String deviceId,
|
||||
}) async {
|
||||
final data = await DioClient.post(
|
||||
'/auth/register',
|
||||
'/register/mobile',
|
||||
data: {
|
||||
'phone': phone,
|
||||
'mobile': phone,
|
||||
'code': code,
|
||||
'password': password,
|
||||
'deviceId': deviceId,
|
||||
},
|
||||
);
|
||||
final result = LoginResult.fromJson(data as Map<String, dynamic>);
|
||||
@@ -85,16 +82,31 @@ class AuthRepositoryImpl implements AuthRepository {
|
||||
required String phone,
|
||||
required SmsScene scene,
|
||||
}) async {
|
||||
final resp = await DioClient.post(
|
||||
'/auth/sms',
|
||||
// 后端按场景拆分验证码发送接口(query 参数 mobile)
|
||||
final path = switch (scene) {
|
||||
SmsScene.login => 'auth/login/sms/code',
|
||||
SmsScene.register => 'auth/register/sms/code',
|
||||
SmsScene.resetPassword => '/reset-password/sms/code',
|
||||
};
|
||||
await DioClient.post(
|
||||
path,
|
||||
queryParameters: {'mobile': phone},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> resetPassword({
|
||||
required String phone,
|
||||
required String code,
|
||||
required String password,
|
||||
}) async {
|
||||
await DioClient.post(
|
||||
'/reset-password',
|
||||
data: {
|
||||
'phone': phone,
|
||||
'scene': scene == SmsScene.register ? 'register' : 'login',
|
||||
'mobile': phone,
|
||||
'code': code,
|
||||
'password': password,
|
||||
},
|
||||
);
|
||||
// 后台成功时 data 可为空,仅做类型校验以防结构异常。
|
||||
if (resp is! Map<String, dynamic> && resp != null) {
|
||||
throw const ApiException(code: -1, message: '短信接口返回异常');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user