新增手机号码注册,手机号码验证码登录
(cherry picked from commit 8e269ab2807642d77a109d6bead0ff12915f1dd7)
This commit is contained in:
parent
9ef53abad5
commit
3f838d224c
@ -75,6 +75,9 @@ class KRLoginController extends GetxController
|
||||
/// 登陆进度状态
|
||||
var kr_loginStatus = KRLoginProgressStatus.kr_registerSendCode.obs;
|
||||
|
||||
/// 是否使用密码登录(手机号模式下有效:true=密码登录,false=验证码登录)
|
||||
var kr_isPasswordLogin = true.obs;
|
||||
|
||||
/// 验证码倒计时
|
||||
var _countdown = 60; // 倒计时初始值
|
||||
late Timer _timer;
|
||||
@ -172,8 +175,8 @@ class KRLoginController extends GetxController
|
||||
}
|
||||
// 如果没有匹配的 entry 值,则保持默认的 kr_loginByPsd 状态
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 初始化计时器
|
||||
_timer = Timer(Duration.zero, () {});
|
||||
|
||||
|
||||
@ -107,6 +107,39 @@ class KRAuthApi {
|
||||
return right(baseResponse.model.kr_token.toString());
|
||||
}
|
||||
|
||||
/// 手机号注册(手机号+区号+密码+验证码,邀请码可选)
|
||||
Future<Either<HttpError, String>> kr_telephoneRegister(
|
||||
String telephone,
|
||||
String areaCode,
|
||||
String password,
|
||||
String code,
|
||||
{String? inviteCode}) async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['telephone'] = telephone;
|
||||
data['telephone_area_code'] = areaCode;
|
||||
data['password'] = password;
|
||||
data['code'] = code;
|
||||
data["identifier"] = KRDeviceInfoService().deviceId ?? 'unknown';
|
||||
|
||||
// 邀请码是可选的
|
||||
if (inviteCode != null && inviteCode.isNotEmpty) {
|
||||
data["invite"] = inviteCode;
|
||||
}
|
||||
|
||||
// cf_token 为空字符串(如果后续需要可以添加)
|
||||
data["cf_token"] = "";
|
||||
|
||||
BaseResponse<KRLoginData> baseResponse = await HttpUtil.getInstance()
|
||||
.request<KRLoginData>('/v1/auth/register/telephone', data,
|
||||
method: HttpMethod.POST, isShowLoading: true);
|
||||
if (!baseResponse.isSuccess) {
|
||||
return left(
|
||||
HttpError(msg: baseResponse.retMsg, code: baseResponse.retCode));
|
||||
}
|
||||
|
||||
return right(baseResponse.model.kr_token.toString());
|
||||
}
|
||||
|
||||
/// 验证验证码(仅支持邮箱)
|
||||
Future<Either<HttpError, bool>> kr_checkVerificationCode(
|
||||
String email, String code, int type) async {
|
||||
@ -151,6 +184,52 @@ class KRAuthApi {
|
||||
return right(baseResponse.model.kr_token.toString());
|
||||
}
|
||||
|
||||
/// 手机号密码登录(手机号+区号+密码)
|
||||
Future<Either<HttpError, String>> kr_telephoneLogin(
|
||||
String telephone, String areaCode, String password) async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['telephone'] = telephone;
|
||||
data['telephone_area_code'] = areaCode;
|
||||
data['password'] = password;
|
||||
|
||||
final deviceId = KRDeviceInfoService().deviceId ?? 'unknown';
|
||||
KRLogUtil.kr_i('设备ID: $deviceId', tag: 'KRAuthApi');
|
||||
data["identifier"] = deviceId;
|
||||
|
||||
BaseResponse<KRLoginData> baseResponse = await HttpUtil.getInstance()
|
||||
.request<KRLoginData>('/v1/auth/login/telephone', data,
|
||||
method: HttpMethod.POST, isShowLoading: true);
|
||||
if (!baseResponse.isSuccess) {
|
||||
return left(
|
||||
HttpError(msg: baseResponse.retMsg, code: baseResponse.retCode));
|
||||
}
|
||||
|
||||
return right(baseResponse.model.kr_token.toString());
|
||||
}
|
||||
|
||||
/// 手机号验证码登录(手机号+区号+验证码)
|
||||
Future<Either<HttpError, String>> kr_telephoneCodeLogin(
|
||||
String telephone, String areaCode, String code) async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['telephone'] = telephone;
|
||||
data['telephone_area_code'] = areaCode;
|
||||
data['telephone_code'] = code;
|
||||
|
||||
final deviceId = KRDeviceInfoService().deviceId ?? 'unknown';
|
||||
KRLogUtil.kr_i('设备ID: $deviceId', tag: 'KRAuthApi');
|
||||
data["identifier"] = deviceId;
|
||||
|
||||
BaseResponse<KRLoginData> baseResponse = await HttpUtil.getInstance()
|
||||
.request<KRLoginData>('/v1/auth/login/telephone', data,
|
||||
method: HttpMethod.POST, isShowLoading: true);
|
||||
if (!baseResponse.isSuccess) {
|
||||
return left(
|
||||
HttpError(msg: baseResponse.retMsg, code: baseResponse.retCode));
|
||||
}
|
||||
|
||||
return right(baseResponse.model.kr_token.toString());
|
||||
}
|
||||
|
||||
/// 发送验证码(仅支持邮箱)
|
||||
/// type: 1=登录, 2=注册, 3=重置密码
|
||||
Future<Either<HttpError, bool>> kr_sendCode(String email, int type) async {
|
||||
@ -169,6 +248,26 @@ class KRAuthApi {
|
||||
return right(true);
|
||||
}
|
||||
|
||||
/// 发送短信验证码(支持手机号)
|
||||
/// type: 1=注册, 2=验证登录
|
||||
Future<Either<HttpError, bool>> kr_sendSmsCode(
|
||||
String telephone, String areaCode, int type) async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['telephone'] = telephone;
|
||||
data['telephone_area_code'] = areaCode;
|
||||
data['type'] = type;
|
||||
|
||||
BaseResponse<dynamic> baseResponse = await HttpUtil.getInstance()
|
||||
.request<dynamic>('/v1/common/send_sms_code', data,
|
||||
method: HttpMethod.POST, isShowLoading: true);
|
||||
if (!baseResponse.isSuccess) {
|
||||
return left(
|
||||
HttpError(msg: baseResponse.retMsg, code: baseResponse.retCode));
|
||||
}
|
||||
|
||||
return right(true);
|
||||
}
|
||||
|
||||
/// 删除账号
|
||||
Future<Either<HttpError, String>> kr_deleteAccount(String email, String code) async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user