25-1/13/1-securejordan

This commit is contained in:
Hamza-Ayed
2025-01-13 22:10:47 +03:00
parent e8c3f8f339
commit a893e49282
36 changed files with 803 additions and 447 deletions

View File

@@ -28,6 +28,9 @@ class CRUD {
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
},
);
Log.print('request: ${response.request}');
Log.print('response: ${response.body}');
Log.print('payload: ${payload}');
// if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
@@ -221,6 +224,9 @@ class CRUD {
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
},
);
Log.print('request: ${response.request}');
Log.print('response: ${response.body}');
Log.print('payload: ${payload}');
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {
if (jsonData['status'] == 'success') {

View File

@@ -1,24 +1,80 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:get_storage/get_storage.dart';
import '../../constant/box_name.dart';
class DeviceController {
String deviceSerialNumber = '';
final box = GetStorage();
class DeviceInfo {
final String? manufacturer;
final String? model;
final String? deviceId;
final String? osVersion;
final String? platform;
final String? deviceName;
final bool? isPhysicalDevice;
void getDeviceSerialNumber() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
DeviceInfo({
this.manufacturer,
this.model,
this.deviceId,
this.osVersion,
this.platform,
this.deviceName,
this.isPhysicalDevice,
});
Map<String, dynamic> toJson() => {
'manufacturer': manufacturer,
'model': model,
'deviceId': deviceId,
'osVersion': osVersion,
'platform': platform,
'deviceName': deviceName,
'isPhysicalDevice': isPhysicalDevice,
};
}
class DeviceController {
final box = GetStorage();
final _deviceInfo = DeviceInfoPlugin();
Future<DeviceInfo> getDeviceInfo() async {
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
deviceSerialNumber = androidInfo.serialNumber;
box.write(BoxName.deviceInfo, deviceSerialNumber.toString());
return await _getAndroidDeviceInfo();
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
deviceSerialNumber = iosInfo.identifierForVendor!;
box.write(BoxName.deviceInfo, deviceSerialNumber.toString());
return await _getIosDeviceInfo();
}
throw UnsupportedError('Unsupported platform');
}
Future<DeviceInfo> _getAndroidDeviceInfo() async {
final androidInfo = await _deviceInfo.androidInfo;
final deviceInfo = DeviceInfo(
manufacturer: androidInfo.manufacturer,
model: androidInfo.model,
deviceId: androidInfo.serialNumber,
osVersion: androidInfo.version.release,
platform: 'Android',
deviceName: androidInfo.device,
isPhysicalDevice: androidInfo.isPhysicalDevice,
);
box.write(BoxName.deviceInfo, deviceInfo.toJson());
return deviceInfo;
}
Future<DeviceInfo> _getIosDeviceInfo() async {
final iosInfo = await _deviceInfo.iosInfo;
final deviceInfo = DeviceInfo(
manufacturer: 'Apple',
model: iosInfo.model,
deviceId: iosInfo.identifierForVendor,
osVersion: iosInfo.systemVersion,
platform: 'iOS',
deviceName: iosInfo.name,
isPhysicalDevice: iosInfo.isPhysicalDevice,
);
box.write(BoxName.deviceInfo, deviceInfo.toJson());
return deviceInfo;
}
}

View File

@@ -0,0 +1,52 @@
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/foundation.dart';
import '../../env/env.dart';
var secretKey = Env.keyOfApp
.toString()
.split('XrXlBl')[0]; // Must be 16 characters for AES-128
const initializationVector = 'abcdefghijklmnop'; // Must be 16 characters
final encryptionHelper = EncryptionHelper(
secretKey: secretKey,
initializationVector: initializationVector,
);
class EncryptionHelper {
final encrypt.Key key;
final encrypt.IV iv;
EncryptionHelper(
{required String secretKey, required String initializationVector})
: key = encrypt.Key.fromUtf8(secretKey),
iv = encrypt.IV.fromUtf8(initializationVector);
// Initialize the helper
/// Encrypts the given plain text
String encryptData(String plainText) {
try {
final encrypter = encrypt.Encrypter(encrypt.AES(key,
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
final encrypted = encrypter.encrypt(plainText, iv: iv);
return encrypted.base64;
} catch (e) {
debugPrint('Encryption Error: $e');
return '';
}
}
/// Decrypts the given encrypted text
String decryptData(String encryptedText) {
try {
final encrypter = encrypt.Encrypter(encrypt.AES(key,
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
final encrypted = encrypt.Encrypted.fromBase64(encryptedText);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
return decrypted;
} catch (e) {
debugPrint('Decryption Error: $e');
return '';
}
}
}

View File

@@ -5,6 +5,7 @@ import 'package:sefer_driver/main.dart';
import 'package:http/http.dart' as http;
import '../../constant/links.dart';
import 'encrypt_decrypt.dart';
import 'upload_image.dart';
Future<String> faceDetector() async {
@@ -23,9 +24,9 @@ Future<String> faceDetector() async {
request.body = json.encode({
"url1":
"https://api.sefer.live/sefer/card_image/id_front-${box.read(BoxName.driverID)}.jpg",
"${AppLink.seferCairoServer}/card_image/id_front-${encryptionHelper.decryptData(box.read(BoxName.driverID))}.jpg",
"url2":
"https://api.sefer.live/sefer/card_image/face_detect-${box.read(BoxName.driverID)}.jpg"
"https://api.sefer.live/sefer/card_image/face_detect-${encryptionHelper.decryptData(box.read(BoxName.driverID))}.jpg"
});
print('request.body: ${request.body}');
request.headers.addAll(headers);

View File

@@ -29,6 +29,7 @@ import '../../constant/api_key.dart';
import '../../constant/char_map.dart';
import '../../constant/colors.dart';
import '../../print.dart';
import 'encrypt_decrypt.dart';
import 'tts.dart';
import 'upload_image.dart';
@@ -393,12 +394,12 @@ class AI extends GetxController {
update();
var payload = {
'first_name':
responseNonIdCardFront['full_name']?.toString().split(' ')[0] ??
'Not specified',
'last_name':
responseNonIdCardFront['full_name']?.toString().split(' ').last ??
'Not specified',
'first_name': encryptionHelper.encryptData(
responseNonIdCardFront['full_name'].toString().split(' ')[0]) ??
'Not specified',
'last_name': encryptionHelper.encryptData(
responseNonIdCardFront['full_name'].toString().split(' ').last) ??
'Not specified',
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
'phone': box.read(BoxName.phoneDriver)?.toString() ?? 'Not specified',
'id': box.read(BoxName.driverID)?.toString() ?? 'Not specified',
@@ -409,12 +410,16 @@ class AI extends GetxController {
.passwordController
.text
.toString(),
'gender': responseNonIdCardFront['gender']?.toString() ?? 'Not specified',
'gender': encryptionHelper
.encryptData(responseNonIdCardFront['gender'].toString()) ??
'Not specified',
'license_type': 'Foreign',
'national_number':
responseNonIdCardFront['passport_no']?.toString() ?? 'Not specified',
'name_arabic':
responseNonIdCardFront['full_name']?.toString() ?? 'Not specified',
'national_number': encryptionHelper
.encryptData(responseNonIdCardFront['passport_no'].toString()) ??
'Not specified',
'name_arabic': encryptionHelper
.encryptData(responseNonIdCardFront['full_name'].toString()) ??
'Not specified',
'name_english': 'Not specified',
'issue_date':
responseNonIdCardBack['issueDate']?.toString() ?? 'Not specified',
@@ -426,24 +431,32 @@ class AI extends GetxController {
? responseIdEgyptDriverLicense['license_categories'].join(', ')
: responseIdEgyptDriverLicense['license_categories']?.toString() ??
'Not specified',
'address':
responseNonIdCardFront['address']?.toString() ?? 'Not specified',
'card_id':
responseNonIdCardFront['card_id']?.toString() ?? 'Not specified',
'occupation':
responseNonIdCardBack['workStatus']?.toString() ?? 'Not specified',
'address': encryptionHelper
.encryptData(responseNonIdCardFront['address'].toString()) ??
'Not specified',
'card_id': encryptionHelper
.encryptData(responseNonIdCardFront['card_id'].toString()) ??
'Not specified',
'occupation': encryptionHelper
.encryptData(responseNonIdCardBack['workStatus'].toString()) ??
'Not specified',
'education': 'Not specified',
'licenseIssueDate':
responseNonIdCardBack['issueDate']?.toString() ?? 'Not specified',
'religion':
responseNonIdCardFront['country']?.toString() ?? 'Not specified',
'religion': encryptionHelper
.encryptData(responseNonIdCardFront['country'].toString()) ??
'Not specified',
'status': 'yet',
'birthdate':
responseNonIdCardFront['birthdate']?.toString() ?? 'Not specified',
'birthdate': encryptionHelper
.encryptData(responseNonIdCardFront['birthdate'].toString()) ??
'Not specified',
'maritalStatus': 'Not specified',
'site': responseNonIdCardFront['address']?.toString() ?? 'Not specified',
'employmentType':
responseNonIdCardBack['residencyType']?.toString() ?? 'Not specified',
'site': encryptionHelper
.encryptData(responseNonIdCardFront['address'].toString()) ??
'Not specified',
'employmentType': encryptionHelper
.encryptData(responseNonIdCardBack['residencyType'].toString()) ??
'Not specified',
};
try {
@@ -486,9 +499,11 @@ class AI extends GetxController {
update();
var payload = {
'first_name': responseIdEgyptDriverLicense['firstName']?.toString() ??
'first_name': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['firstName'].toString()) ??
'Not specified',
'last_name': responseIdEgyptDriverLicense['lastName']?.toString() ??
'last_name': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['lastName'].toString()) ??
'Not specified',
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
'phone': box.read(BoxName.phoneDriver)?.toString() ?? 'Not specified',
@@ -500,17 +515,21 @@ class AI extends GetxController {
.passwordController
.text
.toString(),
'gender': responseIdEgyptBack['gender']?.toString() ?? 'Not specified',
'license_type':
responseIdEgyptDriverLicense['license_type']?.toString() ??
'Not specified',
'national_number':
responseIdEgyptBack['nationalID']?.toString() ?? 'Not specified',
'name_arabic': responseIdEgyptDriverLicense['name_arabic']?.toString() ??
'gender': encryptionHelper
.encryptData(responseIdEgyptBack['gender'].toString()) ??
'Not specified',
'license_type': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['license_type'].toString()) ??
'Not specified',
'national_number': encryptionHelper
.encryptData(responseIdEgyptBack['nationalID'].toString()) ??
'Not specified',
'name_arabic': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['name_arabic'].toString()) ??
'Not specified',
'name_english': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['name_english'].toString()) ??
'Not specified',
'name_english':
responseIdEgyptDriverLicense['name_english']?.toString() ??
'Not specified',
'issue_date': responseIdEgyptDriverLicense['issue_date']?.toString() ??
'Not specified',
'expiry_date': responseIdEgyptDriverLicense['expiry_date']?.toString() ??
@@ -520,27 +539,36 @@ class AI extends GetxController {
? responseIdEgyptDriverLicense['license_categories'].join(', ')
: responseIdEgyptDriverLicense['license_categories']?.toString() ??
'Not specified',
'address': responseIdEgyptFront['address']?.toString() ?? 'Not specified',
'card_id': responseIdEgyptFront['card_id']?.toString() ?? 'Not specified',
'occupation':
responseIdEgyptBack['occupation']?.toString() ?? 'Not specified',
'education':
responseIdEgyptBack['occupation']?.toString() ?? 'Not specified',
'licenseIssueDate':
responseIdEgyptDriverLicense['issue_date']?.toString() ??
'Not specified',
'religion':
responseIdEgyptBack['religion']?.toString() ?? 'Not specified',
'status': 'yet',
'birthdate': extractDOB(
responseIdEgyptDriverLicense['national_number'].toString()),
'maritalStatus':
responseIdEgyptBack['maritalStatus']?.toString() ?? 'Not specified',
'site': responseIdEgyptDriverLicense['address']?.toString() ??
'address': encryptionHelper
.encryptData(responseIdEgyptFront['address'].toString()) ??
'Not specified',
'employmentType':
responseIdEgyptDriverLicense['employmentType']?.toString() ??
'card_id': encryptionHelper
.encryptData(responseIdEgyptFront['card_id'].toString()) ??
'Not specified',
'occupation': encryptionHelper
.encryptData(responseIdEgyptBack['occupation'].toString()) ??
'Not specified',
'education': encryptionHelper
.encryptData(responseIdEgyptBack['occupation'].toString()) ??
'Not specified',
'licenseIssueDate':
responseIdEgyptDriverLicense['issue_date'].toString() ??
'Not specified',
'religion': encryptionHelper
.encryptData(responseIdEgyptBack['religion'].toString()) ??
'Not specified',
'status': 'yet',
'birthdate': encryptionHelper.encryptData(extractDOB(
responseIdEgyptDriverLicense['national_number'].toString())),
'maritalStatus': encryptionHelper
.encryptData(responseIdEgyptBack['maritalStatus'].toString()) ??
'Not specified',
'site': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['address'].toString()) ??
'Not specified',
'employmentType': encryptionHelper.encryptData(
responseIdEgyptDriverLicense['employmentType'].toString()) ??
'Not specified',
};
try {
@@ -583,7 +611,8 @@ class AI extends GetxController {
var res = await CRUD().post(link: AppLink.addCriminalDocuments, payload: {
"driverId": box.read(BoxName.driverID),
"IssueDate": responseCriminalRecordEgypt['IssueDate'],
"InspectionResult": responseCriminalRecordEgypt['InspectionResult'],
"InspectionResult": encryptionHelper
.encryptData(responseCriminalRecordEgypt['InspectionResult']),
});
if (res != 'failure') {
mySnackbarSuccess('uploaded sucssefuly'.tr);
@@ -597,16 +626,21 @@ class AI extends GetxController {
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
'driverID': box.read(BoxName.driverID),
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
'car_plate': responseIdCardDriverEgyptFront['car_plate'].toString(),
'make': responseIdCardDriverEgyptBack['make'].toString(),
'model': responseIdCardDriverEgyptBack['model'],
'car_plate': encryptionHelper.encryptData(
responseIdCardDriverEgyptFront['car_plate'].toString()),
'make': encryptionHelper
.encryptData(responseIdCardDriverEgyptBack['make'].toString()),
'model': encryptionHelper
.encryptData(responseIdCardDriverEgyptBack['model']),
'year': responseIdCardDriverEgyptBack['year'].toString(),
'expiration_date':
responseIdCardDriverEgyptFront['LicenseExpirationDate'].toString(),
'color': responseIdCardDriverEgyptBack['color'],
'owner': responseIdCardDriverEgyptFront['owner'],
'owner': encryptionHelper
.encryptData(responseIdCardDriverEgyptFront['owner']),
'color_hex': responseIdCardDriverEgyptBack['color_hex'].toString(),
'address': responseIdCardDriverEgyptFront['address'].toString(),
'address': encryptionHelper
.encryptData(responseIdCardDriverEgyptFront['address'].toString()),
'displacement': responseIdCardDriverEgyptBack['engine'].toString(),
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
'registration_date':
@@ -624,19 +658,23 @@ class AI extends GetxController {
payload: {
'driverID': box.read(BoxName.driverID),
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
'car_plate':
responseIdCardDriverEgyptFront['car_plate'].toString(),
'make': responseIdCardDriverEgyptBack['make'].toString(),
'model': responseIdCardDriverEgyptBack['model'],
'car_plate': encryptionHelper.encryptData(
responseIdCardDriverEgyptFront['car_plate'].toString()),
'make': encryptionHelper.encryptData(
responseIdCardDriverEgyptBack['make'].toString()),
'model': encryptionHelper
.encryptData(responseIdCardDriverEgyptBack['model']),
'year': responseIdCardDriverEgyptBack['year'].toString(),
'expiration_date':
responseIdCardDriverEgyptFront['LicenseExpirationDate']
.toString(),
'color': responseIdCardDriverEgyptBack['color'],
'owner': responseIdCardDriverEgyptFront['owner'],
'owner': encryptionHelper
.encryptData(responseIdCardDriverEgyptFront['owner']),
'color_hex':
responseIdCardDriverEgyptBack['color_hex'].toString(),
'address': responseIdCardDriverEgyptFront['address'].toString(),
'address': encryptionHelper.encryptData(
responseIdCardDriverEgyptFront['address'].toString()),
'displacement':
responseIdCardDriverEgyptBack['engine'].toString(),
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
@@ -648,19 +686,23 @@ class AI extends GetxController {
payload: {
'driverID': box.read(BoxName.driverID),
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
'car_plate':
responseIdCardDriverEgyptFront['car_plate'].toString(),
'make': responseIdCardDriverEgyptBack['make'].toString(),
'model': responseIdCardDriverEgyptBack['model'],
'car_plate': encryptionHelper.encryptData(
responseIdCardDriverEgyptFront['car_plate'].toString()),
'make': encryptionHelper.encryptData(
responseIdCardDriverEgyptBack['make'].toString()),
'model': encryptionHelper
.encryptData(responseIdCardDriverEgyptBack['model']),
'year': responseIdCardDriverEgyptBack['year'].toString(),
'expiration_date':
responseIdCardDriverEgyptFront['LicenseExpirationDate']
.toString(),
'color': responseIdCardDriverEgyptBack['color'],
'owner': responseIdCardDriverEgyptFront['owner'],
'owner': encryptionHelper
.encryptData(responseIdCardDriverEgyptFront['owner']),
'color_hex':
responseIdCardDriverEgyptBack['color_hex'].toString(),
'address': responseIdCardDriverEgyptFront['address'].toString(),
'address': encryptionHelper.encryptData(
responseIdCardDriverEgyptFront['address'].toString()),
'displacement':
responseIdCardDriverEgyptBack['engine'].toString(),
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),

View File

@@ -43,25 +43,62 @@ class LocationController extends GetxController {
isActive = Get.put(HomeCaptainController()).isActive;
}
// String getLocationArea(double latitude, double longitude) {
// if (latitude >= 29.918901 &&
// latitude <= 30.198857 &&
// longitude >= 31.215009 &&
// longitude <= 31.532186) {
// return 'Cairo';
// } else if (latitude >= 29.904975 &&
// latitude <= 30.143372 &&
// longitude >= 30.787030 &&
// longitude <= 31.215009) {
// return 'Giza';
// } else if (latitude >= 30.396286 &&
// latitude <= 31.654458 &&
// longitude >= 29.041139 &&
// longitude <= 32.626259) {
// return 'Alexandria';
// } else {
// return 'Cairo';
// }
// }
String getLocationArea(double latitude, double longitude) {
if (latitude >= 29.918901 &&
latitude <= 30.198857 &&
longitude >= 31.215009 &&
longitude <= 31.532186) {
return 'Cairo';
} else if (latitude >= 29.904975 &&
latitude <= 30.143372 &&
longitude >= 30.787030 &&
longitude <= 31.215009) {
return 'Giza';
} else if (latitude >= 30.396286 &&
latitude <= 31.654458 &&
longitude >= 29.041139 &&
longitude <= 32.626259) {
return 'Alexandria';
} else {
return 'Cairo';
final locations = box.read(BoxName.locationName) ?? [];
for (final location in locations) {
final locationData = location as Map<String, dynamic>;
// Debugging: Print location data
print('Location Data: $locationData');
// Convert string values to double
final minLatitude =
double.tryParse(locationData['min_latitude'].toString()) ?? 0.0;
final maxLatitude =
double.tryParse(locationData['max_latitude'].toString()) ?? 0.0;
final minLongitude =
double.tryParse(locationData['min_longitude'].toString()) ?? 0.0;
final maxLongitude =
double.tryParse(locationData['max_longitude'].toString()) ?? 0.0;
// Debugging: Print converted values
// print(
// 'Converted Values: minLatitude=$minLatitude, maxLatitude=$maxLatitude, minLongitude=$minLongitude, maxLongitude=$maxLongitude');
if (latitude >= minLatitude &&
latitude <= maxLatitude &&
longitude >= minLongitude &&
longitude <= maxLongitude) {
box.write(BoxName.serverChosen, locationData['server_link']);
// Log.print(
// 'locationData----server_link: ${locationData['server_link']}');
return locationData['name'];
}
}
// Default case
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
return 'Cairo';
}
Future<void> startLocationUpdates() async {
@@ -83,50 +120,30 @@ class LocationController extends GetxController {
if (myLocation == null) {
return;
}
print(
'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
// print(
// 'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
String area =
getLocationArea(myLocation.latitude, myLocation.longitude);
print('Determined Area: $area');
String endpoint;
switch (area) {
case 'Cairo':
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
endpoint = AppLink.addCarsLocationCairoEndpoint;
break;
case 'Giza':
box.write(BoxName.serverChosen, AppLink.seferGizaServer);
endpoint = AppLink.addCarsLocationGizaEndpoint;
break;
case 'Alexandria':
box.write(
BoxName.serverChosen, AppLink.seferAlexandriaServer);
endpoint = AppLink.addCarsLocationAlexandriaEndpoint;
break;
default:
endpoint = AppLink.addCarsLocationCairoEndpoint;
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
}
Log.print('Final Endpoint: $endpoint');
if (box.read(BoxName.driverID) != null) {
await CRUD().post(link: endpoint, payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance == 0 && (speed * 3.6) < 5
? '0.0'
: totalDistance < 7
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation).toString(),
});
await CRUD().post(
link: box.read(BoxName.serverChosen) +
'/ride/location/add.php',
payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance == 0 && (speed * 3.6) < 5
? '0.0'
: totalDistance < 7
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation) ?? 'off',
});
Get.find<HomeCaptainController>()
.mapHomeCaptainController

View File

@@ -14,6 +14,7 @@ import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/my_textField.dart';
import '../../constant/style.dart';
import 'encrypt_decrypt.dart';
class LogOutController extends GetxController {
TextEditingController checkTxtController = TextEditingController();
@@ -30,7 +31,8 @@ class LogOutController extends GetxController {
checkBeforeDelete() async {
var res = await CRUD().post(
link: AppLink.deletecaptainAccounr,
payload: {'id': box.read(BoxName.driverID)}).then((value) => exit(0));
payload: {'id': box.read(BoxName.driverID)});
return res['message'][0]['id'];
}
deletecaptainAccount() {
@@ -72,9 +74,15 @@ class LogOutController extends GetxController {
),
confirm: MyElevatedButton(
title: 'Delete'.tr,
onPressed: () {
if (checkTxtController.text == box.read(BoxName.nameDriver)) {
deletecaptainAccount();
onPressed: () async {
if (checkTxtController.text ==
encryptionHelper.decryptData(box.read(BoxName.nameDriver))) {
// deletecaptainAccount();
var id = await checkBeforeDelete();
deleteMyAccountDriver(id);
} else {
mySnackeBarError('Your Name is Wrong'.tr);
}
}));
}

View File

@@ -2,8 +2,10 @@ import 'dart:convert';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import 'crud.dart';
class SecureStorage {
@@ -28,35 +30,24 @@ const List<String> keysToFetch = [
];
class AppInitializer {
// final FlutterSecureStorage _storage = const FlutterSecureStorage();
List<Map<String, dynamic>> links = [];
Future<void> initializeApp() async {
// Check if app is running for the first time
// Loop through the keys and fetch their values
for (String key in keysToFetch) {
try {
String? value = await getKey(key); // Fetch from server
if (value != null) {
await box.write(key, value); // Save securely
}
} catch (e) {
print('Error fetching or saving key $key: $e');
}
}
await getKey();
}
Future<String?> getKey(String key) async {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
if (res != 'failure') {
try {
var data = jsonDecode(res)['message'];
return data[key]?.toString();
} catch (e) {
print('Error parsing response for $key: $e');
Future<void> getKey() async {
try {
var res =
await CRUD().get(link: AppLink.getLocationAreaLinks, payload: {});
Log.print('res: ${res}');
if (res != 'failure') {
links = List<Map<String, dynamic>>.from(jsonDecode(res)['message']);
await box.remove(BoxName.locationName);
await box.write(BoxName.locationName, links);
}
} catch (e) {
print('Error fetching or decoding location data: $e');
}
return null;
}
}

View File

@@ -11,8 +11,8 @@ import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import '../../print.dart';
import '../auth/captin/login_captin_controller.dart';
import 'encrypt_decrypt.dart';
class SmsEgyptController extends GetxController {
var headers = {'Content-Type': 'application/json'};
@@ -46,11 +46,13 @@ class SmsEgyptController extends GetxController {
if (jsonDecode(res.body)['message'].toString() != "Success") {
await CRUD().post(link: AppLink.updatePhoneInvalidSMS, payload: {
"phone_number":
'+2${Get.find<RegisterCaptainController>().phoneController.text}'
"phone_number": encryptionHelper.encryptData(
'+2${Get.find<RegisterCaptainController>().phoneController.text}')
});
box.write(BoxName.phoneDriver,
'+2${Get.find<RegisterCaptainController>().phoneController.text}');
box.write(
BoxName.phoneDriver,
encryptionHelper.encryptData(
'+2${Get.find<RegisterCaptainController>().phoneController.text}'));
box.write(BoxName.phoneVerified, '1');
await Get.put(LoginDriverController()).loginWithGoogleCredential(

View File

@@ -16,6 +16,7 @@ import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../main.dart';
import '../../print.dart';
import 'encrypt_decrypt.dart';
class ImageController extends GetxController {
File? myImage;
@@ -419,7 +420,8 @@ class ImageController extends GetxController {
compressedImage,
{
'driverID':
box.read(BoxName.driverID) ?? box.read(BoxName.passengerID),
encryptionHelper.decryptData(box.read(BoxName.driverID)) ??
encryptionHelper.decryptData(box.read(BoxName.passengerID)),
'imageType': imageType
},
link,
@@ -458,7 +460,8 @@ class ImageController extends GetxController {
'image',
stream,
length,
filename: '${box.read(BoxName.driverID)}.jpg',
filename:
'${encryptionHelper.decryptData(box.read(BoxName.driverID))}.jpg',
),
);
data.forEach((key, value) {