117 lines
3.9 KiB
Dart
Executable File
117 lines
3.9 KiB
Dart
Executable File
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get_core/src/get_main.dart';
|
|
import 'package:get/get_navigation/src/extension_navigation.dart';
|
|
import 'package:get/get_utils/get_utils.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
import 'package:star_lock/login/register/entity/SendValidationCodeEntity.dart';
|
|
import 'package:star_lock/login/selectCountryRegion/common/index.dart';
|
|
import 'package:star_lock/mine/mine/safeVerify/safeVerify_state.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
import '../../../login/login/entity/LoginData.dart';
|
|
|
|
class SafeVerifyLogic extends BaseGetXController {
|
|
final SafeVerifyState state = SafeVerifyState();
|
|
|
|
late Timer _timer;
|
|
void _startTimer() {
|
|
_timer = Timer.periodic(1.seconds, (timer) {
|
|
if (state.currentSecond > 1) {
|
|
state.currentSecond--;
|
|
} else {
|
|
_cancelTimer();
|
|
state.currentSecond = state.totalSeconds;
|
|
}
|
|
state.resetResend();
|
|
});
|
|
}
|
|
|
|
void _cancelTimer() {
|
|
_timer.cancel();
|
|
}
|
|
|
|
//获取验证码请求
|
|
void sendValidationCode() async {
|
|
final SendValidationCodeEntity entity = await ApiRepository.to.sendValidationCodeAuth(
|
|
countryCode: '',
|
|
account: '',
|
|
channel: state.channel.value,
|
|
codeType: state.codeType.value,
|
|
xWidth: state.xWidth.value.toString());
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
_startTimer();
|
|
} else {}
|
|
}
|
|
|
|
//删除账号请求
|
|
Future<void> deleteAccountRequest() async {
|
|
final LoginEntity entity =
|
|
await ApiRepository.to.deleteAccount(state.channel.value, state.verificationCode.value);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('验证成功,账号已删除'.tr);
|
|
//删除账号成功,
|
|
Get.offNamedUntil(Routers.starLockLoginPage, (route) => false);
|
|
}
|
|
}
|
|
|
|
void checkNext(TextEditingController controller) {
|
|
changeInput(controller);
|
|
}
|
|
|
|
void changeInput(TextEditingController controller) {
|
|
if (controller == state.codeController) {
|
|
state.verificationCode.value = controller.text;
|
|
}
|
|
_resetCanSub();
|
|
}
|
|
|
|
void _resetCanSub() {
|
|
state.canSub.value = state.codeIsOK;
|
|
}
|
|
|
|
///本地存储 登录信息
|
|
void saveLoginData(LoginData? data) async {
|
|
await Storage.setString(saveUserLoginData, jsonEncode(data));
|
|
state.loginData.value = data!;
|
|
}
|
|
|
|
///初始化本地数据
|
|
void initLoginData() async {
|
|
final String? data = await Storage.getString(saveUserLoginData);
|
|
if (data != null && data.isNotEmpty) {
|
|
state.loginData.value = LoginData.fromJson(jsonDecode(data));
|
|
bool mobileIsNotEmpty = state.loginData.value.mobile != null && state.loginData.value.mobile!.isNotEmpty;
|
|
bool emailIsNotEmpty = state.loginData.value.email != null && state.loginData.value.email!.isNotEmpty;
|
|
//有手机号无邮箱 优先显示手机号 不可切换
|
|
if (mobileIsNotEmpty == true && emailIsNotEmpty == false) {
|
|
state.accountStr.value = state.loginData.value.mobile!;
|
|
state.channel.value = '1';
|
|
state.isToggle.value = false;
|
|
} else if (mobileIsNotEmpty == true && emailIsNotEmpty == true) {
|
|
//有手机号有邮箱 优先显示手机号 可切换至邮箱
|
|
state.accountStr.value = state.loginData.value.mobile!;
|
|
state.channel.value = '1';
|
|
state.isToggle.value = true;
|
|
} else if (mobileIsNotEmpty == false && emailIsNotEmpty == true) {
|
|
//无手机号有邮箱 优先显示邮箱 不可切换
|
|
state.accountStr.value = state.loginData.value.email!;
|
|
state.channel.value = '2';
|
|
state.isToggle.value = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
|
|
initLoginData();
|
|
}
|
|
}
|