- 清理大量废弃的 barrel 导出文件,移除冗余的中间导出层 - 修复所有相对路径导入错误,统一调整为扁平化模块引用 - 更新多平台 pubspec 版本号与依赖库版本 - 补充后端功能问题管理后台与脚本工具 - 调整部分页面的快捷方式文案适配新功能 - 更新部分翻译覆盖率与API文档
401 lines
10 KiB
Dart
401 lines
10 KiB
Dart
/// ============================================================
|
||
/// 闲言APP — 认证服务门面
|
||
/// 创建时间: 2026-04-29
|
||
/// 更新时间: 2026-05-15
|
||
/// 作用: 统一认证入口,委托给UserSecurityService和UserCenterService
|
||
/// 上次更新: v10.1.0 新增密保问题接口+多验证方式支持
|
||
/// ============================================================
|
||
|
||
import '../models/user_model.dart';
|
||
import '../../../core/services/auth/token_service.dart';
|
||
import 'user_security_service.dart';
|
||
import '../../user_center/services/user_center_service.dart';
|
||
|
||
class AuthService {
|
||
AuthService._();
|
||
|
||
// ============================================================
|
||
// 登录
|
||
// ============================================================
|
||
|
||
/// 账号密码登录
|
||
static Future<UserModel> login({
|
||
required String account,
|
||
required String password,
|
||
String? deviceName,
|
||
String? deviceModel,
|
||
String? platform,
|
||
String? appName,
|
||
String? deviceId,
|
||
}) async {
|
||
return UserSecurityService.login(
|
||
account: account,
|
||
password: password,
|
||
deviceName: deviceName,
|
||
deviceModel: deviceModel,
|
||
platform: platform,
|
||
appName: appName,
|
||
deviceId: deviceId,
|
||
);
|
||
}
|
||
|
||
/// 回执登录 (无需密码)
|
||
static Future<UserModel> receiptLogin({
|
||
required String account,
|
||
String? deviceName,
|
||
String? deviceModel,
|
||
String? platform,
|
||
String? appName,
|
||
String? deviceId,
|
||
}) async {
|
||
return UserSecurityService.receiptLogin(
|
||
account: account,
|
||
deviceName: deviceName,
|
||
deviceModel: deviceModel,
|
||
platform: platform,
|
||
appName: appName,
|
||
deviceId: deviceId,
|
||
);
|
||
}
|
||
|
||
/// 手机号登录
|
||
static Future<UserModel> mobileLogin({
|
||
required String mobile,
|
||
required String captcha,
|
||
String? deviceName,
|
||
String? deviceModel,
|
||
String? platform,
|
||
String? appName,
|
||
String? deviceId,
|
||
}) async {
|
||
return UserSecurityService.mobileLogin(
|
||
mobile: mobile,
|
||
captcha: captcha,
|
||
deviceName: deviceName,
|
||
deviceModel: deviceModel,
|
||
platform: platform,
|
||
appName: appName,
|
||
deviceId: deviceId,
|
||
);
|
||
}
|
||
|
||
/// Token令牌登录
|
||
static Future<UserModel> tokenLogin(
|
||
String token, {
|
||
String? deviceName,
|
||
String? deviceModel,
|
||
String? platform,
|
||
String? appName,
|
||
String? deviceId,
|
||
}) async {
|
||
return UserSecurityService.tokenLogin(
|
||
token,
|
||
deviceName: deviceName,
|
||
deviceModel: deviceModel,
|
||
platform: platform,
|
||
appName: appName,
|
||
deviceId: deviceId,
|
||
);
|
||
}
|
||
|
||
/// 第三方平台登录
|
||
static Future<UserModel> thirdLogin({
|
||
required String platform,
|
||
required String code,
|
||
}) async {
|
||
return UserSecurityService.thirdLogin(platform: platform, code: code);
|
||
}
|
||
|
||
/// 退出登录
|
||
static Future<void> logout() async {
|
||
await UserSecurityService.logout();
|
||
}
|
||
|
||
// ============================================================
|
||
// 注册
|
||
// ============================================================
|
||
|
||
/// 注册新用户 (回执验证)
|
||
static Future<UserModel> register({
|
||
required String username,
|
||
required String password,
|
||
required String email,
|
||
String? mobile,
|
||
String? mobileCode,
|
||
int? secQuestion,
|
||
String? secAnswer,
|
||
}) async {
|
||
return UserSecurityService.register(
|
||
username: username,
|
||
password: password,
|
||
email: email,
|
||
mobile: mobile,
|
||
mobileCode: mobileCode,
|
||
secQuestion: secQuestion,
|
||
secAnswer: secAnswer,
|
||
);
|
||
}
|
||
|
||
// ============================================================
|
||
// 密码管理
|
||
// ============================================================
|
||
|
||
/// 修改密码 (支持多验证方式)
|
||
static Future<void> changePassword({
|
||
required String newPassword,
|
||
String? oldPassword,
|
||
String? secAnswer,
|
||
String? userId,
|
||
String verifyMethod = 'password',
|
||
}) async {
|
||
return UserSecurityService.changePassword(
|
||
newPassword: newPassword,
|
||
oldPassword: oldPassword,
|
||
secAnswer: secAnswer,
|
||
userId: userId,
|
||
verifyMethod: verifyMethod,
|
||
);
|
||
}
|
||
|
||
/// 重置密码
|
||
static Future<void> resetPassword({
|
||
required String newPassword,
|
||
String type = 'email',
|
||
String? email,
|
||
String? mobile,
|
||
}) async {
|
||
return UserSecurityService.resetPassword(
|
||
newPassword: newPassword,
|
||
type: type,
|
||
email: email,
|
||
mobile: mobile,
|
||
);
|
||
}
|
||
|
||
// ============================================================
|
||
// 邮箱/手机变更
|
||
// ============================================================
|
||
|
||
/// 修改邮箱 (支持回执/密保验证)
|
||
static Future<Map<String, dynamic>> changeEmail({
|
||
required String email,
|
||
String verifyMethod = 'receipt',
|
||
String? secAnswer,
|
||
String? userId,
|
||
}) async {
|
||
return UserCenterService.changeEmail(
|
||
email: email,
|
||
verifyMethod: verifyMethod,
|
||
secAnswer: secAnswer,
|
||
);
|
||
}
|
||
|
||
/// 修改手机号 (回执验证)
|
||
static Future<Map<String, dynamic>> changeMobile({
|
||
required String mobile,
|
||
}) async {
|
||
return UserCenterService.changeMobile(mobile: mobile);
|
||
}
|
||
|
||
// ============================================================
|
||
// 验证码
|
||
// ============================================================
|
||
|
||
/// 发送邮箱验证码
|
||
static Future<void> sendEms({
|
||
required String email,
|
||
required String event,
|
||
}) async {
|
||
return UserSecurityService.sendEms(email: email, event: event);
|
||
}
|
||
|
||
/// 校验邮箱验证码
|
||
static Future<bool> checkEms({
|
||
required String email,
|
||
required String captcha,
|
||
required String event,
|
||
}) async {
|
||
return UserSecurityService.checkEms(
|
||
email: email,
|
||
captcha: captcha,
|
||
event: event,
|
||
);
|
||
}
|
||
|
||
/// 发送短信验证码
|
||
static Future<void> sendSms({required String mobile}) async {
|
||
return UserSecurityService.sendSms(mobile: mobile);
|
||
}
|
||
|
||
// ============================================================
|
||
// 二维码登录 (v9.0.0新增)
|
||
// ============================================================
|
||
|
||
/// 生成二维码
|
||
static Future<QrcodeGenerateResult> qrcodeGenerate() async {
|
||
return UserSecurityService.qrcodeGenerate();
|
||
}
|
||
|
||
/// 扫码确认
|
||
static Future<void> qrcodeConfirm({
|
||
required String code,
|
||
String? platform,
|
||
String? deviceName,
|
||
String? appName,
|
||
}) async {
|
||
return UserSecurityService.qrcodeConfirm(
|
||
code: code,
|
||
platform: platform,
|
||
deviceName: deviceName,
|
||
appName: appName,
|
||
);
|
||
}
|
||
|
||
/// 轮询二维码状态
|
||
static Future<QrcodePollResult> qrcodePoll({required String code}) async {
|
||
return UserSecurityService.qrcodePoll(code: code);
|
||
}
|
||
|
||
/// 取消二维码
|
||
static Future<void> qrcodeCancel({required String code}) async {
|
||
return UserSecurityService.qrcodeCancel(code: code);
|
||
}
|
||
|
||
// ============================================================
|
||
// 账号注销 (v9.0.0新增)
|
||
// ============================================================
|
||
|
||
/// 申请账号注销 (3天审核期)
|
||
static Future<Map<String, dynamic>> requestDeletion({
|
||
required String userId,
|
||
String? reason,
|
||
}) async {
|
||
return UserSecurityService.requestDeletion(userId: userId, reason: reason);
|
||
}
|
||
|
||
/// 查询注销状态
|
||
static Future<Map<String, dynamic>> deletionStatus() async {
|
||
return UserSecurityService.deletionStatus();
|
||
}
|
||
|
||
/// 取消注销申请
|
||
static Future<void> cancelDeletion() async {
|
||
return UserSecurityService.cancelDeletion();
|
||
}
|
||
|
||
// ============================================================
|
||
// 设备管理 (v1.5.0新增)
|
||
// ============================================================
|
||
|
||
/// 设备操作
|
||
static Future<Map<String, dynamic>> devices({
|
||
required String action,
|
||
int? deviceId,
|
||
}) async {
|
||
return UserCenterService.devices(action: action, deviceId: deviceId);
|
||
}
|
||
|
||
/// 注册设备
|
||
static Future<Map<String, dynamic>> registerDevice({
|
||
required String deviceId,
|
||
String? deviceName,
|
||
String? deviceModel,
|
||
String? platform,
|
||
String? appName,
|
||
}) async {
|
||
return UserCenterService.registerDevice(
|
||
deviceId: deviceId,
|
||
deviceName: deviceName,
|
||
deviceModel: deviceModel,
|
||
platform: platform,
|
||
appName: appName,
|
||
);
|
||
}
|
||
|
||
// ============================================================
|
||
// 用户信息
|
||
// ============================================================
|
||
|
||
/// 获取用户信息
|
||
static Future<Map<String, dynamic>> getUserInfo() async {
|
||
return UserCenterService.getUserInfo();
|
||
}
|
||
|
||
/// 修改个人信息
|
||
static Future<Map<String, dynamic>> updateProfile({
|
||
String? username,
|
||
String? nickname,
|
||
String? bio,
|
||
String? avatarUrl,
|
||
}) async {
|
||
return UserCenterService.updateProfile(
|
||
username: username,
|
||
nickname: nickname,
|
||
bio: bio,
|
||
avatarUrl: avatarUrl,
|
||
);
|
||
}
|
||
|
||
/// 获取缓存用户
|
||
static UserModel? getCachedUser() {
|
||
return UserSecurityService.getCachedUser();
|
||
}
|
||
|
||
static Future<void> clearCachedUser() {
|
||
return UserSecurityService.clearCachedUser();
|
||
}
|
||
|
||
/// 验证本地Token是否有效
|
||
static Future<bool> validateLocalToken() async {
|
||
try {
|
||
final info = await getUserInfo();
|
||
return info.isNotEmpty;
|
||
} catch (_) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// 尝试自动登录(使用已存储的Token)
|
||
static Future<bool> tryAutoLogin() async {
|
||
return validateLocalToken();
|
||
}
|
||
|
||
/// 刷新Token
|
||
static Future<bool> refreshToken() async {
|
||
return TokenService.refreshToken();
|
||
}
|
||
|
||
/// 检测Token状态
|
||
static Future<TokenCheckResult> checkToken() async {
|
||
return TokenService.checkToken();
|
||
}
|
||
|
||
// ============================================================
|
||
// 密保问题 (v10.1.0新增)
|
||
// ============================================================
|
||
|
||
/// 获取预置密保问题列表
|
||
static Future<List<SecQuestionItem>> secQuestions() async {
|
||
return UserSecurityService.secQuestions();
|
||
}
|
||
|
||
/// 修改/设置密保问题
|
||
static Future<Map<String, dynamic>> changeSecQuestion({
|
||
required int secQuestion,
|
||
required String secAnswer,
|
||
required String verifyMethod,
|
||
String? oldPassword,
|
||
String? secAnswerOld,
|
||
String? userId,
|
||
}) async {
|
||
return UserSecurityService.changeSecQuestion(
|
||
secQuestion: secQuestion,
|
||
secAnswer: secAnswer,
|
||
verifyMethod: verifyMethod,
|
||
oldPassword: oldPassword,
|
||
secAnswerOld: secAnswerOld,
|
||
userId: userId,
|
||
);
|
||
}
|
||
}
|