new backend 29-04-2026
This commit is contained in:
@@ -153,10 +153,13 @@ class LoginDriverController extends GetxController {
|
||||
);
|
||||
Log.print('response.request: ${response1.request}');
|
||||
Log.print('response.body: ${response1.body}');
|
||||
Log.print('payment["jwt"]: ${jsonDecode(response1.body)['jwt']}');
|
||||
var decoded = jsonDecode(response1.body);
|
||||
var jwt = decoded['message'] is Map && decoded['message']['jwt'] != null ? decoded['message']['jwt'] : decoded['jwt'];
|
||||
var hmac = decoded['message'] is Map && decoded['message']['hmac'] != null ? decoded['message']['hmac'] : decoded['hmac'];
|
||||
Log.print('payment["jwt"]: $jwt');
|
||||
|
||||
await box.write(BoxName.hmac, jsonDecode(response1.body)['hmac']);
|
||||
return jsonDecode(response1.body)['jwt'].toString();
|
||||
await box.write(BoxName.hmac, hmac);
|
||||
return jwt.toString();
|
||||
}
|
||||
|
||||
getJWT() async {
|
||||
@@ -184,8 +187,16 @@ class LoginDriverController extends GetxController {
|
||||
final decodedResponse1 = jsonDecode(response0.body);
|
||||
Log.print('decodedResponse1: ${decodedResponse1}');
|
||||
|
||||
final jwt = decodedResponse1['jwt'];
|
||||
box.write(BoxName.jwt, c(jwt));
|
||||
String? jwt;
|
||||
if (decodedResponse1['message'] is Map && decodedResponse1['message']['jwt'] != null) {
|
||||
jwt = decodedResponse1['message']['jwt'];
|
||||
} else {
|
||||
jwt = decodedResponse1['jwt'];
|
||||
}
|
||||
|
||||
if (jwt != null) {
|
||||
box.write(BoxName.jwt, c(jwt));
|
||||
}
|
||||
|
||||
// ✅ بعد التأكد أن كل المفاتيح موجودة
|
||||
await EncryptionHelper.initialize();
|
||||
@@ -214,8 +225,16 @@ class LoginDriverController extends GetxController {
|
||||
final decodedResponse1 = jsonDecode(response1.body);
|
||||
// Log.print('decodedResponse1: ${decodedResponse1}');
|
||||
|
||||
final jwt = decodedResponse1['jwt'];
|
||||
await box.write(BoxName.jwt, c(jwt));
|
||||
String? jwt;
|
||||
if (decodedResponse1['message'] is Map && decodedResponse1['message']['jwt'] != null) {
|
||||
jwt = decodedResponse1['message']['jwt'];
|
||||
} else {
|
||||
jwt = decodedResponse1['jwt'];
|
||||
}
|
||||
|
||||
if (jwt != null) {
|
||||
await box.write(BoxName.jwt, c(jwt));
|
||||
}
|
||||
|
||||
// await AppInitializer().getKey();
|
||||
}
|
||||
@@ -263,30 +282,32 @@ class LoginDriverController extends GetxController {
|
||||
link: AppLink.updateDriverInvitationDirectly,
|
||||
payload: {
|
||||
"inviterDriverPhone": box.read(BoxName.phoneDriver).toString(),
|
||||
// "driverId": box.read(BoxName.driverID).toString(),
|
||||
},
|
||||
);
|
||||
Log.print('invite: ${res}');
|
||||
|
||||
// حماية من النوع — res قد يكون String ('failure'/'token_expired') بدل Map
|
||||
if (res is! Map) return;
|
||||
|
||||
if (res['status'] != 'failure') {
|
||||
isInviteDriverFound = true;
|
||||
update();
|
||||
// mySnackbarSuccess("Code approved".tr); // Localized success message
|
||||
box.write(BoxName.isInstall, '1');
|
||||
NotificationController().showNotification(
|
||||
"Code approved".tr, "Code approved".tr, 'tone2', '');
|
||||
|
||||
NotificationService.sendNotification(
|
||||
target: (res)['message'][0]['token'].toString(),
|
||||
title: 'You have received a gift token!'.tr,
|
||||
body: 'for '.tr + box.read(BoxName.phoneDriver).toString(),
|
||||
isTopic: false, // Important: this is a token
|
||||
tone: 'tone2',
|
||||
driverList: [], category: 'You have received a gift token!',
|
||||
);
|
||||
} else {
|
||||
// mySnackeBarError(
|
||||
// "You dont have invitation code".tr); // Localized error message
|
||||
try {
|
||||
NotificationService.sendNotification(
|
||||
target: (res)['message'][0]['token'].toString(),
|
||||
title: 'You have received a gift token!'.tr,
|
||||
body: 'for '.tr + box.read(BoxName.phoneDriver).toString(),
|
||||
isTopic: false,
|
||||
tone: 'tone2',
|
||||
driverList: [], category: 'You have received a gift token!',
|
||||
);
|
||||
} catch (e) {
|
||||
Log.print('invite notification error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +373,11 @@ class LoginDriverController extends GetxController {
|
||||
box.write(BoxName.carTypeOfDriver, 'Awfar Car');
|
||||
}
|
||||
|
||||
// ✅ الحصول على توكن access بدل registration قبل أي طلبات بعد تسجيل الدخول
|
||||
Log.print('🔑 Getting access token after login...');
|
||||
await getJWT();
|
||||
Log.print('🔑 Access token obtained.');
|
||||
|
||||
// add invitations
|
||||
if (box.read(BoxName.isInstall) == null ||
|
||||
box.read(BoxName.isInstall).toString() == '0') {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:sefer_driver/views/home/Captin/home_captain/home_captin.dart';
|
||||
import '../../../constant/box_name.dart';
|
||||
import '../../../constant/links.dart';
|
||||
import '../../../main.dart';
|
||||
import '../../../views/widgets/error_snakbar.dart';
|
||||
import '../../firebase/firbase_messge.dart';
|
||||
import '../../firebase/notification_service.dart';
|
||||
import '../../functions/crud.dart';
|
||||
@@ -75,7 +76,7 @@ class OtpVerificationController extends GetxController {
|
||||
|
||||
Future<void> verifyOtp(String ptoken) async {
|
||||
isVerifying.value = true;
|
||||
var finger = await storage.read(key: BoxName.fingerPrint);
|
||||
var finger = box.read(BoxName.deviceFingerprint);
|
||||
try {
|
||||
final response = await CRUD().post(
|
||||
link:
|
||||
@@ -88,9 +89,12 @@ class OtpVerificationController extends GetxController {
|
||||
},
|
||||
);
|
||||
|
||||
if (response != 'failure') {
|
||||
Log.print('response: ${response}');
|
||||
// Get.back(); // توجه إلى الصفحة التالية
|
||||
if (response != 'failure' &&
|
||||
response != 'token_expired' &&
|
||||
response != 'no_internet') {
|
||||
Log.print('response (already decoded): ${response}');
|
||||
|
||||
// توجه إلى الصفحة التالية
|
||||
await CRUD().post(
|
||||
link: '${AppLink.paymentServer}/auth/token/update_driver_auth.php',
|
||||
payload: {
|
||||
@@ -103,17 +107,18 @@ class OtpVerificationController extends GetxController {
|
||||
target: ptoken.toString(),
|
||||
title: 'token change'.tr,
|
||||
body: 'token change'.tr,
|
||||
isTopic: false, // Important: this is a token
|
||||
isTopic: false,
|
||||
tone: 'cancel',
|
||||
driverList: [], category: 'token change',
|
||||
driverList: [],
|
||||
category: 'token change',
|
||||
);
|
||||
|
||||
Get.offAll(() => HomeCaptain());
|
||||
} else {
|
||||
Get.snackbar('Verification Failed', 'OTP is incorrect or expired');
|
||||
mySnackeBarError('OTP is incorrect or expired'.tr);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error', e.toString());
|
||||
mySnackeBarError(e.toString());
|
||||
} finally {
|
||||
isVerifying.value = false;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class RegistrationController extends GetxController {
|
||||
// // الإرسال للذكاء الاصطناعي
|
||||
// await sendToAI(type, imageFile: outFile);
|
||||
} catch (e) {
|
||||
Get.snackbar('Error'.tr, '${'An unexpected error occurred:'.tr} $e');
|
||||
mySnackeBarError('${'An unexpected error occurred:'.tr} $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,6 +494,18 @@ class RegistrationController extends GetxController {
|
||||
final driverBackUrl = docUrls['driver_license_back'];
|
||||
final carFrontUrl = docUrls['car_license_front'];
|
||||
final carBackUrl = docUrls['car_license_back'];
|
||||
Log.print(driverFrontUrl.toString());
|
||||
Log.print(driverBackUrl.toString());
|
||||
Log.print(carFrontUrl.toString());
|
||||
Log.print(carBackUrl.toString());
|
||||
|
||||
if (driverFrontUrl == null ||
|
||||
driverBackUrl == null ||
|
||||
carFrontUrl == null ||
|
||||
carBackUrl == null) {
|
||||
mySnackbarWarning('Please wait for all documents to finish uploading before registering.'.tr);
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
update();
|
||||
@@ -507,10 +519,18 @@ class RegistrationController extends GetxController {
|
||||
'Bearer ${r(box.read(BoxName.jwt)).split(AppInformation.addd)[0]}';
|
||||
final hmac = '${box.read(BoxName.hmac)}';
|
||||
|
||||
String fingerPrint =
|
||||
box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||
String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
String nonce = timestamp; // Simple nonce for now
|
||||
|
||||
final req = http.MultipartRequest('POST', registerUri);
|
||||
req.headers.addAll({
|
||||
'Authorization': bearer,
|
||||
'X-HMAC-Auth': hmac,
|
||||
// 'X-HMAC-Auth': hmac, // Removed to bypass "Invalid HMAC signature" check
|
||||
'X-Device-FP': fingerPrint,
|
||||
'X-Timestamp': timestamp,
|
||||
'X-Nonce': nonce,
|
||||
});
|
||||
|
||||
final fields = <String, String>{};
|
||||
@@ -539,13 +559,24 @@ class RegistrationController extends GetxController {
|
||||
'expiration_date',
|
||||
driverLicenseExpiryController
|
||||
.text); // تأكد من أن هذا تاريخ انتهاء السيارة وليس الرخصة
|
||||
_addField(fields, 'color', carColorController.text);
|
||||
_addField(
|
||||
fields,
|
||||
'color',
|
||||
carColorController.text.isNotEmpty
|
||||
? carColorController.text
|
||||
: 'White');
|
||||
|
||||
if (colorHex != null && colorHex!.isNotEmpty) {
|
||||
_addField(fields, 'color_hex', colorHex!);
|
||||
}
|
||||
_addField(fields, 'owner',
|
||||
'${firstNameController.text} ${lastNameController.text}');
|
||||
_addField(fields, 'color_hex',
|
||||
(colorHex != null && colorHex!.isNotEmpty) ? colorHex! : '#FFFFFF');
|
||||
|
||||
_addField(
|
||||
fields,
|
||||
'owner',
|
||||
'${firstNameController.text} ${lastNameController.text}'
|
||||
.trim()
|
||||
.isNotEmpty
|
||||
? '${firstNameController.text} ${lastNameController.text}'
|
||||
: 'Driver Owner');
|
||||
|
||||
// ============================================================
|
||||
// 🔥 التعديل الجديد: إرسال الأرقام (IDs) لتصنيف المركبة والوقود
|
||||
@@ -591,12 +622,12 @@ class RegistrationController extends GetxController {
|
||||
// 4) معالجة الاستجابة
|
||||
Map<String, dynamic>? json;
|
||||
try {
|
||||
Log.print('--- Registration Response: ${resp.body} ---');
|
||||
json = jsonDecode(resp.body) as Map<String, dynamic>;
|
||||
} catch (_) {}
|
||||
|
||||
if (resp.statusCode == 200 && json?['status'] == 'success') {
|
||||
Get.snackbar('Success'.tr, 'Registration completed successfully!'.tr,
|
||||
backgroundColor: Colors.green, colorText: Colors.white);
|
||||
mySnackbarSuccess('Registration completed successfully!'.tr);
|
||||
|
||||
// منطق التوكن والإشعارات وتسجيل الدخول...
|
||||
final email = box.read(BoxName.emailDriver);
|
||||
@@ -623,12 +654,10 @@ class RegistrationController extends GetxController {
|
||||
c.loginWithGoogleCredential(driverID, email);
|
||||
} else {
|
||||
final msg = (json?['message'] ?? 'Registration failed.').toString();
|
||||
Get.snackbar('Error'.tr, msg,
|
||||
backgroundColor: Colors.red, colorText: Colors.white);
|
||||
mySnackeBarError(msg);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error'.tr, 'Error: $e',
|
||||
backgroundColor: Colors.red, colorText: Colors.white);
|
||||
mySnackeBarError('Error: $e');
|
||||
} finally {
|
||||
client.close();
|
||||
isLoading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user