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') {
|
||||
|
||||
Reference in New Issue
Block a user