This commit is contained in:
Hamza-Ayed
2025-03-08 19:35:09 +03:00
parent d41314cfed
commit 5a4664ed67
30 changed files with 433 additions and 306 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
@@ -22,6 +23,16 @@ class CRUD {
required String link,
Map<String, dynamic>? payload,
}) async {
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
Log.print('isTokenExpired: ${isTokenExpired}');
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
// await Get.put(LoginDriverController()).getJWT();
var url = Uri.parse(
link,
);
@@ -34,6 +45,9 @@ class CRUD {
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
},
);
print(response.request);
print(response.body);
print(payload);
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
@@ -48,7 +62,7 @@ class CRUD {
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJWT();
mySnackbarSuccess('please order now'.tr);
// mySnackbarSuccess('please order now'.tr);
return 'token_expired'; // Return a specific value for token expiration
} else {
@@ -92,7 +106,7 @@ class CRUD {
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJwtWallet();
// await Get.put(LoginDriverController()).getJwtWallet();
return 'token_expired'; // Return a specific value for token expiration
} else {
@@ -111,6 +125,13 @@ class CRUD {
{required String link, Map<String, dynamic>? payload}) async {
var url = Uri.parse(link);
try {
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
var response = await http.post(
url,
body: payload,
@@ -121,6 +142,9 @@ class CRUD {
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
},
);
print(response.request);
print(response.body);
print(payload);
if (response.statusCode == 200) {
try {
var jsonData = jsonDecode(response.body);
@@ -139,7 +163,7 @@ class CRUD {
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJWT();
// await Get.put(LoginDriverController()).getJWT();
// MyDialog().getDialog(
// 'Session expired. Please log in again.'.tr,
// '',

View File

@@ -43,8 +43,8 @@ class EncryptionHelper {
/// Encrypts a string
String encryptData(String plainText) {
try {
final encrypter =
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
final encrypter = encrypt.Encrypter(
encrypt.AES(key, mode: encrypt.AESMode.cbc)); // AES-GCM
final encrypted = encrypter.encrypt(plainText, iv: iv);
return encrypted.base64;
} catch (e) {

View File

@@ -1,8 +1,10 @@
import 'dart:convert';
import 'dart:io';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/main.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import '../../constant/links.dart';
import 'encrypt_decrypt.dart';
@@ -13,14 +15,16 @@ Future<String> faceDetector() async {
await Future.delayed(const Duration(seconds: 2));
var headers = {
'Authorization': 'Basic ${AK.basicCompareFaces}',
// 'Authorization': 'Basic ${AK.basicCompareFaces}',
'Authorization': 'Basic hamza:12345678',
'Content-Type': 'application/json'
};
// var request = http.Request('POST', Uri.parse(//Todo
// 'https://face-detect-f6924392c4c7.herokuapp.com/compare_faces'));
var request = http.Request(
'POST',
Uri.parse(
'https://face-detect-f6924392c4c7.herokuapp.com/compare_faces'));
'POST', Uri.parse('https://mohkh.online:5000/compare_faces'));
request.body = json.encode({
"url1":
@@ -32,7 +36,9 @@ Future<String> faceDetector() async {
request.headers.addAll(headers);
try {
http.StreamedResponse response = await request.send();
http.Client client = await createHttpClient();
http.StreamedResponse response = await client.send(request);
// http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
String result = await response.stream.bytesToString();
@@ -47,3 +53,43 @@ Future<String> faceDetector() async {
return 'Error: $e';
}
}
Future<http.Client> createHttpClient() async {
final SecurityContext securityContext = SecurityContext();
HttpClient httpClient = HttpClient(context: securityContext);
httpClient.badCertificateCallback =
(X509Certificate cert, String host, int port) => true; // Bypass SSL
return IOClient(httpClient);
}
Future<String> faceDetector2(String url1, String url2) async {
var headers = {
'Authorization': 'Basic hamza:12345678',
'Content-Type': 'application/json'
};
var request = http.Request(
'POST', Uri.parse('https://mohkh.online:5000/compare_faces'));
request.body = json.encode({"url1": url1, "url2": url2});
request.headers.addAll(headers);
try {
http.Client client = await createHttpClient(); // Use custom client
DateTime startTime = DateTime.now();
http.StreamedResponse response = await client.send(request);
DateTime endTime = DateTime.now();
Duration duration = endTime.difference(startTime);
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
print(duration.inSeconds);
return await response.stream.bytesToString();
} else {
print(await response.stream.bytesToString());
return 'Error: ${response.reasonPhrase}';
}
} catch (e) {
return 'Exception: $e';
}
}

View File

@@ -2,6 +2,9 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/info.dart';
import 'package:sefer_driver/constant/links.dart';
@@ -400,7 +403,10 @@ class AI extends GetxController {
'last_name': EncryptionHelper.instance.encryptData(
responseNonIdCardFront['full_name'].toString().split(' ').last) ??
'Not specified',
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
'email': EncryptionHelper.instance
.encryptData(box.read(BoxName.emailDriver))
?.toString() ??
'Not specified',
'phone': box.read(BoxName.phoneDriver)?.toString() ?? 'Not specified',
'id': box.read(BoxName.driverID)?.toString() ?? 'Not specified',
'password':
@@ -494,9 +500,21 @@ class AI extends GetxController {
}
}
String shortHash(String password) {
var bytes = utf8.encode(password);
var digest = sha256.convert(bytes);
return base64UrlEncode(digest.bytes);
}
Future<void> addDriverEgypt() async {
isLoading = true;
update();
final loginDriverController = Get.put(LoginDriverController());
var pass = loginDriverController.passwordController.text.isEmpty
? '${box.read(BoxName.emailDriver)}${box.read(BoxName.driverID)}'
: '${loginDriverController.emailController.text.toString()}${box.read(BoxName.driverID)}';
String hashedPassword = shortHash(pass);
var payload = {
'first_name': EncryptionHelper.instance.encryptData(
@@ -505,16 +523,13 @@ class AI extends GetxController {
'last_name': EncryptionHelper.instance.encryptData(
responseIdEgyptDriverLicense['lastName'].toString()) ??
'Not specified',
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
'email': EncryptionHelper.instance
.encryptData(box.read(BoxName.emailDriver))
.toString() ??
'Not specified',
'phone': box.read(BoxName.phoneDriver)?.toString() ?? 'Not specified',
'id': box.read(BoxName.driverID)?.toString() ?? 'Not specified',
'password':
Get.put(LoginDriverController()).passwordController.text.isEmpty
? box.read(BoxName.emailDriver).toString()
: Get.find<LoginDriverController>()
.passwordController
.text
.toString(),
'password': hashedPassword.toString(),
'gender': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['gender'].toString()) ??
'Not specified',
@@ -825,7 +840,7 @@ class AI extends GetxController {
var json = jsonDecode(extractedString);
// Log.print('extractedString: ${extractedString}');
var textValues = CRUD().extractTextFromLines(json);
Log.print('textValues: ${textValues}');
Log.print('textValues: $textValues');
// Log.print('json: ${json}');
DocumentType detectedType = checkDocumentType(textValues);
@@ -1141,7 +1156,7 @@ class AI extends GetxController {
jsonDecode(responseData['content'][0]['text']);
} else if (idType == 'non_id_front') {
responseNonIdCardFront = jsonDecode(responseData['content'][0]['text']);
Log.print('responseNonIdCardFront: ${responseNonIdCardFront}');
Log.print('responseNonIdCardFront: $responseNonIdCardFront');
} else if (idType == 'non_id_back') {
responseNonIdCardBack = jsonDecode(responseData['content'][0]['text']);
}

View File

@@ -37,8 +37,12 @@ class LocationController extends GetxController {
void onInit() async {
super.onInit();
location = Location(); // Initialize the location object
await location.changeSettings(
accuracy: LocationAccuracy.high,
interval: 5000, // 5 seconds
distanceFilter: 0);
await getLocation(); // Fetch the location immediately
startLocationUpdates(); // Start periodic location updates
await startLocationUpdates(); // Start periodic location updates
totalPoints = Get.put(CaptainWalletController()).totalPoints.toString();
isActive = Get.put(HomeCaptainController()).isActive;
@@ -70,7 +74,6 @@ class LocationController extends GetxController {
final locationData = location as Map<String, dynamic>;
// Debugging: Print location data
print('Location Data: $locationData');
// Convert string values to double
final minLatitude =
@@ -83,7 +86,6 @@ class LocationController extends GetxController {
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 &&
@@ -92,7 +94,6 @@ class LocationController extends GetxController {
longitude <= maxLongitude) {
box.write(BoxName.serverChosen,
EncryptionHelper.instance.decryptData(locationData['server_link']));
// Log.print(
// 'locationData----server_link: ${locationData['server_link']}');
return locationData['name'];
}
@@ -122,12 +123,10 @@ class LocationController extends GetxController {
if (myLocation == null) {
return;
}
// print(
// 'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
String area =
getLocationArea(myLocation.latitude, myLocation.longitude);
print('Determined Area: $area');
if (box.read(BoxName.driverID) != null) {
await CRUD().post(
@@ -160,9 +159,7 @@ class LocationController extends GetxController {
}
}
}
} catch (e) {
Log.print('Error during location update: $e');
}
} catch (e) {}
});
}
}

View File

@@ -235,12 +235,7 @@ class SecurityHelper {
// debugPrint("Bundle ID: $bundleId"); // Print the bundle ID
// Check for security risks and potentially show a warning
if (isNotTrust ||
isJailBroken ||
isTampered ||
isDevMode ||
isOnExternalStorage ||
!isRealDevice) {
if (isJailBroken || isNotTrust || !isRealDevice || isTampered) {
// print("security_warning".tr); //using easy_localization
// Use a more robust approach to show a warning, like a dialog:
_showSecurityWarning();

View File

@@ -39,16 +39,13 @@ class AppInitializer {
List<Map<String, dynamic>> links = [];
Future<void> initializeApp() async {
Log.print('box.read("jwt"): ${box.read(BoxName.jwt)}');
if (box.read(BoxName.jwt) == null) {
await LoginDriverController().getJWT();
} else {
print('firstTimeLoadKey ${box.read(BoxName.firstTimeLoadKey)}');
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
Log.print('isTokenExpired: $isTokenExpired');
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
@@ -73,7 +70,6 @@ class AppInitializer {
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);
@@ -93,8 +89,6 @@ class AppInitializer {
await box.write(BoxName.paymentLink,
EncryptionHelper.instance.decryptData(links[4]['server_link']));
}
} catch (e) {
print('Error fetching or decoding location data: $e');
}
} catch (e) {}
}
}

View File

@@ -57,7 +57,8 @@ class SmsEgyptController extends GetxController {
await Get.put(LoginDriverController()).loginWithGoogleCredential(
box.read(BoxName.driverID).toString(),
box.read(BoxName.emailDriver).toString(),
EncryptionHelper.instance
.encryptData(box.read(BoxName.emailDriver).toString()),
);
} else {
Get.defaultDialog(