Update: 2026-06-12 20:40:40

This commit is contained in:
Hamza-Ayed
2026-06-12 20:40:40 +03:00
parent 305ae01d52
commit f907212c57
294 changed files with 3592 additions and 3581 deletions

View File

@@ -44,17 +44,14 @@ class RegisterController extends GetxController {
if (res != 'failure' && res is Map && res['status'] == 'success') {
// حفظ كلمة المرور للدخول التلقائي لاحقاً
await storage.write(key: 'password', value: password.text);
Get.defaultDialog(
title: "نجاح",
middleText: res['message']['message'] ?? "تم تقديم طلبك بنجاح. يرجى انتظار موافقة الإدارة.",
onConfirm: () {
Get.back(); // close dialog
Get.back(); // return to login
},
textConfirm: "موافق",
);
// Request OTP
bool otpSent = await _sendOtp(phone.text);
if (otpSent) {
_showOtpDialog(phone.text, res['message']?['message'] ?? "تم تقديم طلبك بنجاح. يرجى انتظار موافقة الإدارة.");
} else {
Get.snackbar('Error', 'Failed to send OTP'.tr);
}
} else {
Get.snackbar(
"خطأ",
@@ -66,6 +63,86 @@ class RegisterController extends GetxController {
}
}
Future<bool> _sendOtp(String phoneNumber) async {
try {
final response = await CRUD().post(
link: '${AppLink.server}/auth/otp/request.php',
payload: {
'receiver': phoneNumber,
'user_type': 'service'
},
);
return response != 'failure';
} catch (e) {
Log.print('OTP SEND ERROR: $e');
return false;
}
}
void _showOtpDialog(String phoneNumber, String successMessage) {
String otpCode = '';
Get.defaultDialog(
title: 'رمز التحقق'.tr,
content: Column(
children: [
Text('تم إرسال رمز التحقق إلى رقمك ($phoneNumber)'.tr),
const SizedBox(height: 16),
TextField(
onChanged: (val) => otpCode = val,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'أدخل الرمز هنا'.tr,
border: OutlineInputBorder(),
),
),
],
),
textConfirm: 'تحقق'.tr,
confirmTextColor: Colors.white,
onConfirm: () async {
if (otpCode.length >= 3) {
Get.back(); // close dialog
await _verifyOtpAndFinalize(phoneNumber, otpCode, successMessage);
} else {
Get.snackbar('خطأ', 'الرجاء إدخال رمز صحيح'.tr);
}
},
);
}
Future<void> _verifyOtpAndFinalize(String phoneNumber, String otp, String successMessage) async {
Get.dialog(const Center(child: CircularProgressIndicator()), barrierDismissible: false);
try {
final response = await CRUD().post(
link: '${AppLink.server}/auth/otp/verify.php',
payload: {
'phone_number': phoneNumber,
'token_code': otp,
'user_type': 'service',
},
);
Get.back(); // close loading
if (response != 'failure' && response['status'] == 'success') {
Get.defaultDialog(
title: "نجاح".tr,
middleText: successMessage,
onConfirm: () {
Get.back(); // close success dialog
Get.back(); // return to login page
},
textConfirm: "موافق".tr,
);
} else {
Get.snackbar('Error', 'Invalid OTP'.tr);
}
} catch (e) {
Get.back(); // close loading
Log.print('OTP VERIFY ERROR: $e');
Get.snackbar('Error', e.toString());
}
}
@override
void onClose() {
firstName.dispose();