9/24/1-backLocation
This commit is contained in:
@@ -94,13 +94,96 @@ class RegisterCaptainController extends GetxController {
|
||||
return validPrefixes.hasMatch(phoneNumber);
|
||||
}
|
||||
|
||||
// sendOtpMessage() async {
|
||||
// SmsEgyptController smsEgyptController = Get.put(SmsEgyptController());
|
||||
// isLoading = true;
|
||||
// update();
|
||||
// int randomNumber = Random().nextInt(100000) + 1;
|
||||
// isLoading = true;
|
||||
// update();
|
||||
// if (formKey3.currentState!.validate()) {
|
||||
// if (box.read(BoxName.countryCode) == 'Egypt') {
|
||||
// if (isValidEgyptianPhoneNumber(phoneController.text)) {
|
||||
// var responseCheker = await CRUD()
|
||||
// .post(link: AppLink.checkPhoneNumberISVerfiedDriver, payload: {
|
||||
// 'phone_number': '+2${phoneController.text}',
|
||||
// });
|
||||
// if (responseCheker != 'failure') {
|
||||
// var d = jsonDecode(responseCheker);
|
||||
// if (d['message'][0]['is_verified'].toString() == '1') {
|
||||
// Get.snackbar('Phone number is verified before'.tr, '',
|
||||
// backgroundColor: AppColor.greenColor);
|
||||
// box.write(BoxName.phoneVerified, '1');
|
||||
// box.write(BoxName.phone, '+2${phoneController.text}');
|
||||
// await Get.put(LoginDriverController()).loginUsingCredentials(
|
||||
// box.read(BoxName.driverID).toString(),
|
||||
// box.read(BoxName.emailDriver).toString(),
|
||||
// );
|
||||
// } else {
|
||||
// await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
|
||||
// 'phone_number': '+2${phoneController.text}',
|
||||
// 'token_code': randomNumber.toString(),
|
||||
// "driverId": box.read(BoxName.driverID),
|
||||
// "email": box.read(BoxName.emailDriver),
|
||||
// });
|
||||
|
||||
// await smsEgyptController.sendSmsEgypt(
|
||||
// phoneController.text.toString(), randomNumber.toString());
|
||||
|
||||
// isSent = true;
|
||||
|
||||
// isLoading = false;
|
||||
// update();
|
||||
// }
|
||||
// } else {
|
||||
// await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
|
||||
// 'phone_number': '+2${phoneController.text}',
|
||||
// 'token_code': randomNumber.toString(),
|
||||
// "driverId": box.read(BoxName.driverID),
|
||||
// "email": box.read(BoxName.emailDriver),
|
||||
// });
|
||||
|
||||
// await smsEgyptController.sendSmsEgypt(
|
||||
// phoneController.text.toString(), randomNumber.toString());
|
||||
|
||||
// isSent = true;
|
||||
|
||||
// isLoading = false;
|
||||
// update();
|
||||
// }
|
||||
// } else {
|
||||
// Get.snackbar('Phone Number wrong'.tr, '',
|
||||
// backgroundColor: AppColor.redColor);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// isLoading = false;
|
||||
// update();
|
||||
// }
|
||||
sendOtpMessage() async {
|
||||
SmsEgyptController smsEgyptController = Get.put(SmsEgyptController());
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
int randomNumber = Random().nextInt(100000) + 1;
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
// Get the current time and the last OTP time (if it exists)
|
||||
DateTime currentTime = DateTime.now();
|
||||
DateTime? lastOtpTime = box.read(BoxName.lastOtpTime);
|
||||
|
||||
// Check if the last OTP was sent within 5 minutes (300 seconds)
|
||||
if (lastOtpTime != null &&
|
||||
currentTime.difference(lastOtpTime).inSeconds < 300) {
|
||||
Get.snackbar(
|
||||
'Please wait'.tr, 'You can send another OTP after 5 minutes.'.tr,
|
||||
backgroundColor: AppColor.redColor);
|
||||
isLoading = false;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (formKey3.currentState!.validate()) {
|
||||
if (box.read(BoxName.countryCode) == 'Egypt') {
|
||||
if (isValidEgyptianPhoneNumber(phoneController.text)) {
|
||||
@@ -108,6 +191,7 @@ class RegisterCaptainController extends GetxController {
|
||||
.post(link: AppLink.checkPhoneNumberISVerfiedDriver, payload: {
|
||||
'phone_number': '+2${phoneController.text}',
|
||||
});
|
||||
|
||||
if (responseCheker != 'failure') {
|
||||
var d = jsonDecode(responseCheker);
|
||||
if (d['message'][0]['is_verified'].toString() == '1') {
|
||||
@@ -120,36 +204,10 @@ class RegisterCaptainController extends GetxController {
|
||||
box.read(BoxName.emailDriver).toString(),
|
||||
);
|
||||
} else {
|
||||
await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
|
||||
'phone_number': '+2${phoneController.text}',
|
||||
'token_code': randomNumber.toString(),
|
||||
"driverId": box.read(BoxName.driverID),
|
||||
"email": box.read(BoxName.emailDriver),
|
||||
});
|
||||
|
||||
await smsEgyptController.sendSmsEgypt(
|
||||
phoneController.text.toString(), randomNumber.toString());
|
||||
|
||||
isSent = true;
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
await _sendOtp(randomNumber, smsEgyptController);
|
||||
}
|
||||
} else {
|
||||
await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
|
||||
'phone_number': '+2${phoneController.text}',
|
||||
'token_code': randomNumber.toString(),
|
||||
"driverId": box.read(BoxName.driverID),
|
||||
"email": box.read(BoxName.emailDriver),
|
||||
});
|
||||
|
||||
await smsEgyptController.sendSmsEgypt(
|
||||
phoneController.text.toString(), randomNumber.toString());
|
||||
|
||||
isSent = true;
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
await _sendOtp(randomNumber, smsEgyptController);
|
||||
}
|
||||
} else {
|
||||
Get.snackbar('Phone Number wrong'.tr, '',
|
||||
@@ -157,6 +215,26 @@ class RegisterCaptainController extends GetxController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
_sendOtp(int randomNumber, SmsEgyptController smsEgyptController) async {
|
||||
await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
|
||||
'phone_number': '+2${phoneController.text}',
|
||||
'token_code': randomNumber.toString(),
|
||||
"driverId": box.read(BoxName.driverID),
|
||||
"email": box.read(BoxName.emailDriver),
|
||||
});
|
||||
|
||||
await smsEgyptController.sendSmsEgypt(
|
||||
phoneController.text.toString(), randomNumber.toString());
|
||||
|
||||
// Save the current time as the last OTP time
|
||||
box.write(BoxName.lastOtpTime, DateTime.now());
|
||||
|
||||
isSent = true;
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user