160 lines
5.4 KiB
Dart
160 lines
5.4 KiB
Dart
// ============================================================
|
|
// Auth Misc UseCases — 登出、Session恢复、验证码、密码管理
|
|
// ============================================================
|
|
|
|
import '../entities/auth_session.dart';
|
|
import '../repositories/auth_repository.dart';
|
|
|
|
// ── Session 恢复 ─────────────────────────────────────────────
|
|
|
|
class RestoreSessionUseCase {
|
|
final IAuthRepository _repository;
|
|
const RestoreSessionUseCase(this._repository);
|
|
|
|
Future<AuthSession?> call() => _repository.restoreSession();
|
|
}
|
|
|
|
// ── 登出 ──────────────────────────────────────────────────────
|
|
|
|
class LogoutUseCase {
|
|
final IAuthRepository _repository;
|
|
const LogoutUseCase(this._repository);
|
|
|
|
Future<void> call() => _repository.logout();
|
|
}
|
|
|
|
// ── SMS 验证码 ────────────────────────────────────────────────
|
|
|
|
class SendSmsCodeParams {
|
|
final String phone;
|
|
final SmsCodeType type;
|
|
const SendSmsCodeParams({required this.phone, required this.type});
|
|
}
|
|
|
|
class SendSmsCodeUseCase {
|
|
final IAuthRepository _repository;
|
|
const SendSmsCodeUseCase(this._repository);
|
|
|
|
Future<int> call(SendSmsCodeParams params) =>
|
|
_repository.sendSmsCode(params.phone, params.type);
|
|
}
|
|
|
|
// ── 邮件验证码 ────────────────────────────────────────────────
|
|
|
|
class SendEmailCodeParams {
|
|
final String email;
|
|
final EmailCodeType type;
|
|
const SendEmailCodeParams({required this.email, required this.type});
|
|
}
|
|
|
|
class SendEmailCodeUseCase {
|
|
final IAuthRepository _repository;
|
|
const SendEmailCodeUseCase(this._repository);
|
|
|
|
Future<int> call(SendEmailCodeParams params) =>
|
|
_repository.sendEmailCode(params.email, params.type);
|
|
}
|
|
|
|
// ── 重置密码(手机) ──────────────────────────────────────────
|
|
|
|
class ResetPasswordParams {
|
|
final String phone;
|
|
final String smsCode;
|
|
final String newPassword;
|
|
const ResetPasswordParams({
|
|
required this.phone,
|
|
required this.smsCode,
|
|
required this.newPassword,
|
|
});
|
|
}
|
|
|
|
class ResetPasswordUseCase {
|
|
final IAuthRepository _repository;
|
|
const ResetPasswordUseCase(this._repository);
|
|
|
|
Future<void> call(ResetPasswordParams params) => _repository.resetPassword(
|
|
phone: params.phone,
|
|
smsCode: params.smsCode,
|
|
newPassword: params.newPassword,
|
|
);
|
|
}
|
|
|
|
// ── 重置密码(邮件)──────────────────────────────────────────
|
|
|
|
class ResetPasswordByEmailParams {
|
|
final String email;
|
|
final String emailCode;
|
|
final String newPassword;
|
|
const ResetPasswordByEmailParams({
|
|
required this.email,
|
|
required this.emailCode,
|
|
required this.newPassword,
|
|
});
|
|
}
|
|
|
|
class ResetPasswordByEmailUseCase {
|
|
final IAuthRepository _repository;
|
|
const ResetPasswordByEmailUseCase(this._repository);
|
|
|
|
Future<void> call(ResetPasswordByEmailParams params) =>
|
|
_repository.resetPasswordByEmail(
|
|
email: params.email,
|
|
emailCode: params.emailCode,
|
|
newPassword: params.newPassword,
|
|
);
|
|
}
|
|
|
|
// ── 修改密码 ──────────────────────────────────────────────────
|
|
|
|
class ChangePasswordParams {
|
|
final String oldPassword;
|
|
final String newPassword;
|
|
const ChangePasswordParams({required this.oldPassword, required this.newPassword});
|
|
}
|
|
|
|
class ChangePasswordUseCase {
|
|
final IAuthRepository _repository;
|
|
const ChangePasswordUseCase(this._repository);
|
|
|
|
Future<void> call(ChangePasswordParams params) => _repository.changePassword(
|
|
oldPassword: params.oldPassword,
|
|
newPassword: params.newPassword,
|
|
);
|
|
}
|
|
|
|
// ── 换绑手机 ──────────────────────────────────────────────────
|
|
|
|
class ChangePhoneParams {
|
|
final String newPhone;
|
|
final String newSmsCode;
|
|
const ChangePhoneParams({required this.newPhone, required this.newSmsCode});
|
|
}
|
|
|
|
class ChangePhoneUseCase {
|
|
final IAuthRepository _repository;
|
|
const ChangePhoneUseCase(this._repository);
|
|
|
|
Future<void> call(ChangePhoneParams params) => _repository.changePhone(
|
|
newPhone: params.newPhone,
|
|
newSmsCode: params.newSmsCode,
|
|
);
|
|
}
|
|
|
|
// ── 推荐码验证 ────────────────────────────────────────────────
|
|
|
|
class ValidateReferralCodeUseCase {
|
|
final IAuthRepository _repository;
|
|
const ValidateReferralCodeUseCase(this._repository);
|
|
|
|
Future<bool> call(String code) => _repository.validateReferralCode(code);
|
|
}
|
|
|
|
// ── 支付宝授权字符串 ──────────────────────────────────────────
|
|
|
|
class GetAlipayAuthStringUseCase {
|
|
final IAuthRepository _repository;
|
|
const GetAlipayAuthStringUseCase(this._repository);
|
|
|
|
Future<String> call() => _repository.getAlipayAuthString();
|
|
}
|