25-12-1/1

This commit is contained in:
Hamza-Ayed
2025-12-01 07:53:52 +03:00
parent 1a0bf1ee32
commit 11dfe94bbb
49 changed files with 19013 additions and 15915 deletions

View File

@@ -87,34 +87,70 @@ class LoginController extends GetxController {
update();
}
getJwtWallet() async {
final random = Random();
Future<String> getJwtWallet() async {
try {
final random = Random();
if (random.nextBool()) {
await SecurityHelper.performSecurityChecks();
} else {
await SecurityChecks.isDeviceRootedFromNative(Get.context!);
// Perform security check randomly
if (random.nextBool()) {
await SecurityHelper.performSecurityChecks();
} else {
await SecurityChecks.isDeviceRootedFromNative(Get.context!);
}
String fingerPrint = await DeviceHelper.getDeviceFingerprint();
final dev = GetPlatform.isAndroid ? 'android' : 'ios';
var payload = {
'id': box.read(BoxName.passengerID),
'password': AK.passnpassenger,
'aud': '${AK.allowed}$dev',
'fingerPrint': fingerPrint,
};
var response = await http.post(
Uri.parse(AppLink.loginJwtWalletRider),
body: payload,
);
// Handle bad responses
if (response.statusCode != 200) {
_showJwtErrorDialog(
"حدث خطأ أثناء الاتصال بالخادم. يرجى المحاولة مرة أخرى.");
throw Exception("JWT request failed");
}
var data = jsonDecode(response.body);
// Validate JWT response structure
if (!data.containsKey('jwt') || !data.containsKey('hmac')) {
_showJwtErrorDialog("تعذّر التحقق من الأمان. يرجى إعادة المحاولة.");
throw Exception("Invalid JWT response format");
}
// Save HMAC locally
await box.write(BoxName.hmac, data['hmac']);
return data['jwt'].toString();
} catch (e) {
_showJwtErrorDialog("حدث خلل غير متوقع. يرجى المحاولة مرة أخرى.");
rethrow;
}
}
String fingerPrint = await DeviceHelper.getDeviceFingerprint();
// print('fingerPrint: ${fingerPrint}');
dev = Platform.isAndroid ? 'android' : 'ios';
var payload = {
'id': box.read(BoxName.passengerID),
'password': AK.passnpassenger,
'aud': '${AK.allowed}$dev',
'fingerPrint': fingerPrint
};
var response1 = await http.post(
Uri.parse(AppLink.loginJwtWalletRider),
body: payload,
void _showJwtErrorDialog(String message) {
if (Get.context == null) return;
Get.defaultDialog(
title: "خطأ في الاتصال",
middleText: message,
textConfirm: "إعادة المحاولة",
confirmTextColor: Colors.white,
onConfirm: () {
Get.back();
getJwtWallet();
},
);
await box.write(BoxName.hmac, jsonDecode(response1.body)['hmac']);
// Log.print('jsonDecoeded[hmac]: ${jsonDecoeded['hmac']}');
// Log.print('req: ${response1.request}');
// Log.print('response: ${response1.body}');
// Log.print('payload: ${payload}');
return jsonDecode(response1.body)['jwt'].toString();
}
getJWT() async {

View File

@@ -19,21 +19,78 @@ class PhoneAuthHelper {
static final String _verifyOtpUrl = '${_baseUrl}verifyOtp.php';
static final String _registerUrl = '${_baseUrl}register_passenger.php';
static String formatSyrianPhone(String phone) {
// Remove spaces, symbols, +, -, ()
phone = phone.replaceAll(RegExp(r'[ \-\(\)\+]'), '').trim();
// Normalize 00963 → 963
if (phone.startsWith('00963')) {
phone = phone.replaceFirst('00963', '963');
}
// Normalize 0963 → 963
if (phone.startsWith('0963')) {
phone = phone.replaceFirst('0963', '963');
}
// NEW: Fix 96309xxxx → 9639xxxx
if (phone.startsWith('96309')) {
phone = '9639' + phone.substring(5); // remove the "0" after 963
}
// If starts with 9630 → correct to 9639
if (phone.startsWith('9630')) {
phone = '9639' + phone.substring(4);
}
// If already in correct format: 9639xxxxxxxx
if (phone.startsWith('9639') && phone.length == 12) {
return phone;
}
// If starts with 963 but missing the 9
if (phone.startsWith('963') && phone.length > 3) {
// Ensure it begins with 9639
if (!phone.startsWith('9639')) {
phone = '9639' + phone.substring(3);
}
return phone;
}
// If starts with 09xxxxxxxx → 9639xxxxxxxx
if (phone.startsWith('09')) {
return '963' + phone.substring(1);
}
// If 9xxxxxxxx (9 digits)
if (phone.startsWith('9') && phone.length == 9) {
return '963' + phone;
}
// If starts with incorrect 0xxxxxxx → assume Syrian and fix
if (phone.startsWith('0') && phone.length == 10) {
return '963' + phone.substring(1);
}
return phone;
}
/// Sends an OTP to the provided phone number.
static Future<bool> sendOtp(String phoneNumber) async {
try {
// Log.print('_sendOtpUrl: ${_sendOtpUrl}');
// Log.print('phoneNumber: ${phoneNumber}');
// إصلاح الرقم قبل الإرسال
final fixedPhone = formatSyrianPhone(phoneNumber);
final response = await CRUD().post(
link: _sendOtpUrl,
payload: {'receiver': phoneNumber},
payload: {'receiver': fixedPhone}, // ← ← استخدام الرقم المُعدّل
);
// Log.print('response: ${response}');
if (response != 'failure') {
final data = (response);
final data = response;
if (data['status'] == 'success') {
mySnackbarSuccess('An OTP has been sent to your WhatsApp number.'.tr);
mySnackbarSuccess('An OTP has been sent to your number.'.tr);
return true;
} else {
mySnackeBarError(data['message'] ?? 'Failed to send OTP.');
@@ -44,19 +101,20 @@ class PhoneAuthHelper {
return false;
}
} catch (e) {
// Log.print('e: ${e}');
// mySnackeBarError('An error occurred: $e');
return false;
}
}
/// Verifies the OTP and logs the user in.
static Future<void> verifyOtp(String phoneNumber, String otp) async {
static Future<void> verifyOtp(String phoneNumber) async {
try {
final fixedPhone = formatSyrianPhone(phoneNumber);
final response = await CRUD().post(
link: _verifyOtpUrl,
payload: {'phone_number': phoneNumber, 'otp': otp},
payload: {
'phone_number': fixedPhone,
},
);
if (response != 'failure') {
@@ -96,13 +154,12 @@ class PhoneAuthHelper {
'passengerID': box.read(BoxName.passengerID).toString(),
"fingerPrint": fingerPrint
});
await CRUD().post(
link: "${AppLink.seferPaymentServer}/ride/firebase/add.php",
payload: {
'token': (box.read(BoxName.tokenFCM.toString())),
'passengerID': box.read(BoxName.passengerID).toString(),
"fingerPrint": fingerPrint
});
await CRUD()
.post(link: "${AppLink.paymentServer}/ride/firebase/add.php", payload: {
'token': (box.read(BoxName.tokenFCM.toString())),
'passengerID': box.read(BoxName.passengerID).toString(),
"fingerPrint": fingerPrint
});
}
static Future<void> registerUser({

View File

@@ -222,19 +222,19 @@ class RegisterController extends GetxController {
if (res1 != 'failure') {
//Multi-server signup (moved inside the successful registration check)
if (AppLink.IntaleqAlexandriaServer != AppLink.IntaleqSyriaServer) {
List<Future> signUp = [
CRUD().post(
link: '${AppLink.IntaleqAlexandriaServer}/auth/signup.php',
payload: payload,
),
CRUD().post(
link: '${AppLink.IntaleqGizaServer}/auth/signup.php',
payload: payload,
)
];
await Future.wait(signUp); // Wait for both sign-ups to complete.
}
// if (AppLink.IntaleqAlexandriaServer != AppLink.IntaleqSyriaServer) {
// List<Future> signUp = [
// CRUD().post(
// link: '${AppLink.IntaleqAlexandriaServer}/auth/signup.php',
// payload: payload,
// ),
// CRUD().post(
// link: '${AppLink.IntaleqGizaServer}/auth/signup.php',
// payload: payload,
// )
// ];
// await Future.wait(signUp); // Wait for both sign-ups to complete.
// }
box.write(BoxName.isVerified, '1');
box.write(
@@ -297,19 +297,19 @@ class RegisterController extends GetxController {
);
if (res1 != 'failure') {
if (AppLink.IntaleqAlexandriaServer != AppLink.IntaleqSyriaServer) {
List<Future> signUp = [
CRUD().post(
link: '${AppLink.IntaleqAlexandriaServer}/auth/signup.php',
payload: payload,
),
CRUD().post(
link: '${AppLink.IntaleqGizaServer}/auth/signup.php',
payload: payload,
)
];
await Future.wait(signUp);
}
// if (AppLink.IntaleqAlexandriaServer != AppLink.IntaleqSyriaServer) {
// List<Future> signUp = [
// CRUD().post(
// link: '${AppLink.IntaleqAlexandriaServer}/auth/signup.php',
// payload: payload,
// ),
// CRUD().post(
// link: '${AppLink.IntaleqGizaServer}/auth/signup.php',
// payload: payload,
// )
// ];
// await Future.wait(signUp);
// }
box.write(BoxName.isVerified, '1');
box.write(BoxName.isFirstTime, '0');

View File

@@ -91,18 +91,8 @@ class OtpVerificationController extends GetxController {
);
if (response != 'failure' && response['status'] == 'success') {
final fcm = Get.isRegistered<FirebaseMessagesController>()
? Get.find<FirebaseMessagesController>()
: Get.put(FirebaseMessagesController());
// await fcm.sendNotificationToDriverMAP(
// 'token change',
// 'change device'.tr,
// ptoken.toString(),
// [],
// 'cancel',
// );
await NotificationService.sendNotification(
category: 'token change',
target: ptoken.toString(),
title: 'token change'.tr,
body: 'change device'.tr,
@@ -110,21 +100,7 @@ class OtpVerificationController extends GetxController {
tone: 'cancel',
driverList: [],
);
await CRUD().post(
link: "${AppLink.seferPaymentServer}/ride/firebase/add.php",
payload: {
'token': (box.read(BoxName.tokenFCM.toString())),
'passengerID': box.read(BoxName.passengerID).toString(),
"fingerPrint": fingerPrint.toString(),
});
// CRUD().post(
// link:
// '${AppLink.seferPaymentServer}/auth/token/update_passenger_token.php',
// payload: {
// 'token': box.read(BoxName.tokenFCM).toString(),
// 'fingerPrint': fingerPrint.toString(),
// 'passengerID': box.read(BoxName.passengerID).toString(),
// });
Get.offAll(() => const MapPagePassenger());
} else {
Get.snackbar('Verification Failed', 'OTP is incorrect or expired');