From 3f838d224cca72e9cb177e89b26ed21067f5f373 Mon Sep 17 00:00:00 2001 From: Rust Date: Fri, 31 Oct 2025 22:54:34 -0700 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E7=A0=81=E6=B3=A8=E5=86=8C=EF=BC=8C=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E7=A0=81=E9=AA=8C=E8=AF=81=E7=A0=81=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 8e269ab2807642d77a109d6bead0ff12915f1dd7) --- .../controllers/kr_login_controller.dart | 7 +- lib/app/services/api_service/kr_auth_api.dart | 99 +++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/lib/app/modules/kr_login/controllers/kr_login_controller.dart b/lib/app/modules/kr_login/controllers/kr_login_controller.dart index f1e9f90..4bf6dde 100755 --- a/lib/app/modules/kr_login/controllers/kr_login_controller.dart +++ b/lib/app/modules/kr_login/controllers/kr_login_controller.dart @@ -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, () {}); diff --git a/lib/app/services/api_service/kr_auth_api.dart b/lib/app/services/api_service/kr_auth_api.dart index f312b5f..d5a5a6d 100755 --- a/lib/app/services/api_service/kr_auth_api.dart +++ b/lib/app/services/api_service/kr_auth_api.dart @@ -107,6 +107,39 @@ class KRAuthApi { return right(baseResponse.model.kr_token.toString()); } + /// 手机号注册(手机号+区号+密码+验证码,邀请码可选) + Future> kr_telephoneRegister( + String telephone, + String areaCode, + String password, + String code, + {String? inviteCode}) async { + final Map data = {}; + 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 baseResponse = await HttpUtil.getInstance() + .request('/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> kr_checkVerificationCode( String email, String code, int type) async { @@ -151,6 +184,52 @@ class KRAuthApi { return right(baseResponse.model.kr_token.toString()); } + /// 手机号密码登录(手机号+区号+密码) + Future> kr_telephoneLogin( + String telephone, String areaCode, String password) async { + final Map data = {}; + 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 baseResponse = await HttpUtil.getInstance() + .request('/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> kr_telephoneCodeLogin( + String telephone, String areaCode, String code) async { + final Map data = {}; + 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 baseResponse = await HttpUtil.getInstance() + .request('/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> kr_sendCode(String email, int type) async { @@ -169,6 +248,26 @@ class KRAuthApi { return right(true); } + /// 发送短信验证码(支持手机号) + /// type: 1=注册, 2=验证登录 + Future> kr_sendSmsCode( + String telephone, String areaCode, int type) async { + final Map data = {}; + data['telephone'] = telephone; + data['telephone_area_code'] = areaCode; + data['type'] = type; + + BaseResponse baseResponse = await HttpUtil.getInstance() + .request('/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> kr_deleteAccount(String email, String code) async { final Map data = {};