# Conflicts: # android/app/src/main/AndroidManifest.xml # lib/login/login/starLock_login_logic.dart # lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart # lib/main/lockDetail/doorLockLog/doorLockLog_page.dart # lib/main/lockDetail/lockDetail/lockDetail_logic.dart # lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart # lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_page.dart # lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart # lib/mine/mineSet/mineSet/mineSet_logic.dart # lib/tools/advancedCalendar/src/widget.dart # pubspec.yaml
158 lines
5.1 KiB
Dart
Executable File
158 lines
5.1 KiB
Dart
Executable File
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
|
import 'package:star_lock/blue/blue_manage.dart';
|
|
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
import 'package:star_lock/login/register/entity/SendValidationCodeEntity.dart';
|
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
import 'package:umeng_common_sdk/umeng_common_sdk.dart';
|
|
|
|
import '../../network/api_repository.dart';
|
|
import '../../tools/baseGetXController.dart';
|
|
import '../../tools/dateTool.dart';
|
|
import '../../tools/regularExpression.dart';
|
|
import '../../tools/showTipView.dart';
|
|
import 'entity/checkIP_entity.dart';
|
|
import 'starLock_register_state.dart';
|
|
|
|
class StarLockRegisterLogic extends BaseGetXController {
|
|
final StarLockRegisterState state = StarLockRegisterState();
|
|
|
|
late Timer _timer;
|
|
void _startTimer() {
|
|
_timer = Timer.periodic(1.seconds, (Timer timer) {
|
|
if (state.currentSecond > 1) {
|
|
state.currentSecond--;
|
|
} else {
|
|
_cancelTimer();
|
|
state.currentSecond = state.totalSeconds;
|
|
}
|
|
state.resetResend();
|
|
});
|
|
}
|
|
|
|
void _cancelTimer() {
|
|
_timer.cancel();
|
|
// _timer = null;
|
|
}
|
|
|
|
Future<void> register() async {
|
|
if (state.pwd.value != state.surePwd.value) {
|
|
showToast('密码不一致哦'.tr);
|
|
return;
|
|
}
|
|
|
|
if(!RegularExpression().validateString(state.pwd.value)){
|
|
showToast('密码需至少包含数字/字母/字符中的2种组合'.tr);
|
|
return;
|
|
}
|
|
final LoginEntity entity = await ApiRepository.to.register(
|
|
receiverType: state.isIphoneType.value == true ? 1 : 2,
|
|
countryCode: int.parse(state.countryCode.value),
|
|
account: state.phoneOrEmailStr.value,
|
|
password: state.pwd.value,
|
|
verificationCode: state.verificationCode.value,
|
|
deviceInfo: state.deviceInfoMap.value);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
UmengCommonSdk.onEvent('register_result', {
|
|
'account':state.phoneOrEmailStr.value,
|
|
'date':DateTool().getNowDateWithType(1),
|
|
'register_res':'成功',
|
|
});
|
|
|
|
Storage.saveLoginData(entity.data);
|
|
Storage.setBool(saveIsVip, entity.data!.isVip == 1);
|
|
eventBus.fire(MineInfoChangeRefreshUI());
|
|
XSJPushProvider().initLocalNotification(isCancelLocalPush: false);
|
|
Get.offNamedUntil(Routers.starLockMain, (Route route) => false);
|
|
BlueManage().scanDevices.clear(); //清除设备缓存
|
|
}else{
|
|
UmengCommonSdk.onEvent('register_result', {
|
|
'account':state.phoneOrEmailStr.value,
|
|
'date':DateTool().getNowDateWithType(1),
|
|
'register_res':'${entity.errorCode}--${entity.errorMsg}',
|
|
});
|
|
}
|
|
}
|
|
|
|
Future<void> sendValidationCode() async {
|
|
final SendValidationCodeEntity entity =
|
|
await ApiRepository.to.sendValidationCodeUnLogin(
|
|
// state.countryCode.value,
|
|
countryCode: state.countryCode.value.toString(),
|
|
account: state.phoneOrEmailStr.value,
|
|
channel: state.isIphoneType.value ? '1' : '2',
|
|
codeType: '1',
|
|
xWidth: state.xWidth.value.toString());
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
_startTimer();
|
|
} else {}
|
|
}
|
|
|
|
Future<void> checkIpAction() async {
|
|
final CheckIPEntity entity = await ApiRepository.to.checkIpAction(ip: '');
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
if (state.countryName.value == entity.data!.name) {
|
|
ShowTipView().showSureAlertDialog(
|
|
'国家地区的选择将影响数据安全,你当前选择的是阿尔巴尼亚,请确认后再继续'.tr,
|
|
tipTitle: '确认国家或地区'.tr,
|
|
sureStr: '我知道了'.tr);
|
|
}
|
|
}
|
|
}
|
|
|
|
void changeAgreeState() {
|
|
_resetCanSub();
|
|
}
|
|
|
|
void checkNext(TextEditingController controller) {
|
|
changeInput(controller);
|
|
}
|
|
|
|
void changeInput(TextEditingController controller) {
|
|
if (controller == state.phoneOrEmailController) {
|
|
state.phoneOrEmailStr.value = controller.text;
|
|
}
|
|
if (controller == state.pwdController) {
|
|
state.pwd.value = controller.text;
|
|
}
|
|
if (controller == state.sureController) {
|
|
state.surePwd.value = controller.text;
|
|
}
|
|
if (controller == state.codeController) {
|
|
state.verificationCode.value = controller.text;
|
|
}
|
|
_resetCanSub();
|
|
_resetCanSendCode();
|
|
}
|
|
|
|
// 重置是否能提交
|
|
void _resetCanSub() {
|
|
state.canSub.value = state.pwdIsOK && state.codeIsOK && state.phoneOrEmailStr.value.isNotEmpty;
|
|
}
|
|
|
|
// 重置是否能发送验证码
|
|
void _resetCanSendCode() {
|
|
state.canSendCode.value = state.pwdIsOK && state.phoneOrEmailStr.value.isNotEmpty;
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
|
|
XSConstantMacro().getDeviceInfoData().then((Map<String, dynamic> data) {
|
|
state.deviceInfoMap.value = data;
|
|
}).catchError((error) {
|
|
// 适当处理错误
|
|
AppLog.log('获取设备信息时出错: $error');
|
|
});
|
|
}
|
|
}
|