|
|
|
@ -67,7 +67,6 @@ class LoginController extends GetxController { |
|
|
|
|
|
|
|
_contactValue.value = contactController.text; |
|
|
|
_formatDisplayContact(); |
|
|
|
_startCountdown(); |
|
|
|
_sendVerificationCode(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -133,7 +132,7 @@ class LoginController extends GetxController { |
|
|
|
_contactValue.value = contactController.text; |
|
|
|
_formatDisplayContact(); |
|
|
|
_viewState.value = LoginViewState.verification; |
|
|
|
_startCountdown(); |
|
|
|
|
|
|
|
_sendVerificationCode(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -185,14 +184,26 @@ class LoginController extends GetxController { |
|
|
|
Future<void> _sendVerificationCode() async { |
|
|
|
// 这里应该是实际发送验证码的逻辑 |
|
|
|
// 为了演示,我们只是模拟发送 |
|
|
|
var response = await Api.getCode({ |
|
|
|
"addr": contactController.text, |
|
|
|
"vtype": 0, |
|
|
|
}); |
|
|
|
if (response != null) { |
|
|
|
print("请求后台数据验证码params=${response}"); |
|
|
|
//短信已发送 |
|
|
|
//EasyLoading.showInfo('codeSend'.tr); |
|
|
|
if (isEmialContactController() || isPhoneContactController()) { |
|
|
|
_startCountdown(); |
|
|
|
var response = await Api.getCode({ |
|
|
|
"addr": contactController.text, |
|
|
|
"vtype": 0, |
|
|
|
}); |
|
|
|
if (response != null) { |
|
|
|
print("请求后台数据验证码params=${response}"); |
|
|
|
//短信已发送 |
|
|
|
//EasyLoading.showInfo('codeSend'.tr); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Get.snackbar( |
|
|
|
'提示', |
|
|
|
'请正确的手机号码或邮箱', |
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
colorText: Colors.red, |
|
|
|
); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -205,6 +216,7 @@ class LoginController extends GetxController { |
|
|
|
|
|
|
|
// 更新验证码输入 |
|
|
|
void updateVerificationCode(int index, String value) { |
|
|
|
print("updateVerificationCode=${index}${value}"); |
|
|
|
if (index >= 0 && index < 4) { |
|
|
|
var newList = [..._verificationCode]; |
|
|
|
newList[index] = value; |
|
|
|
@ -217,25 +229,32 @@ class LoginController extends GetxController { |
|
|
|
_verificationCode.value = ['', '', '', '']; |
|
|
|
} |
|
|
|
|
|
|
|
// 检查邮箱格式 |
|
|
|
bool isEmialContactController() { |
|
|
|
// 检查每个元素是否为单个字母或数字字符 |
|
|
|
final text = contactController.text; |
|
|
|
return (text.length > 5 && |
|
|
|
RegExp(r'^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') |
|
|
|
.hasMatch(text)) || |
|
|
|
(RegExp(r'^[z0-9]$').hasMatch(text)); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查手机号码格式 |
|
|
|
bool isPhoneContactController() { |
|
|
|
// 检查每个元素是否为单个字母或数字字符 |
|
|
|
final text = contactController.text; |
|
|
|
return RegExp(r'^[0-9]+$').hasMatch(text); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查验证码是否完整 |
|
|
|
bool isVerificationCodeComplete() { |
|
|
|
return !_verificationCode.contains(''); |
|
|
|
// 检查每个元素是否为单个字母或数字字符 |
|
|
|
final text = verificationCodeController.text; |
|
|
|
return text.length == 4 && RegExp(r'^[A-Za-z0-9]$').hasMatch(text); |
|
|
|
} |
|
|
|
|
|
|
|
// 登录 |
|
|
|
Future<void> login() async { |
|
|
|
// 暂时关闭验证码验证 |
|
|
|
// if (!isVerificationCodeComplete()) { |
|
|
|
// Get.snackbar( |
|
|
|
// '提示', |
|
|
|
// '请输入完整的验证码', |
|
|
|
// snackPosition: SnackPosition.TOP, |
|
|
|
// backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
// colorText: Colors.red, |
|
|
|
// ); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
|
|
|
|
_isLoading.value = true; |
|
|
|
|
|
|
|
try { |
|
|
|
@ -245,16 +264,16 @@ class LoginController extends GetxController { |
|
|
|
switch (loginType) { |
|
|
|
case 0 || 1: |
|
|
|
{ |
|
|
|
// if (!isVerificationCodeComplete()) { |
|
|
|
// Get.snackbar( |
|
|
|
// '提示', |
|
|
|
// '请输入完整的验证码', |
|
|
|
// snackPosition: SnackPosition.TOP, |
|
|
|
// backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
// colorText: Colors.red, |
|
|
|
// ); |
|
|
|
// break; |
|
|
|
// } |
|
|
|
if (!isVerificationCodeComplete()) { |
|
|
|
Get.snackbar( |
|
|
|
'提示', |
|
|
|
'请输入完整的验证码', |
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
colorText: Colors.red, |
|
|
|
); |
|
|
|
break; |
|
|
|
} |
|
|
|
requestLogin({ |
|
|
|
"mail": contactController.text, |
|
|
|
"phone": "", |
|
|
|
|