25-1/28/1

This commit is contained in:
Hamza-Ayed
2025-01-28 01:03:39 +03:00
parent 63681f104c
commit f217b5a34f
102 changed files with 7253 additions and 3945 deletions

View File

@@ -30,7 +30,9 @@ class CRUD {
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
},
);
// Log.print('req: ${response.request}');
// Log.print('response: ${response.body}');
// Log.print('payload: ${payload}');
// if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
@@ -40,6 +42,46 @@ class CRUD {
return jsonData['status'];
}
Future<dynamic> post({
required String link,
Map<String, dynamic>? payload,
}) async {
var url = Uri.parse(link);
try {
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
},
);
if (response.statusCode == 200) {
try {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return jsonData;
} else {
return jsonData['status'];
}
} catch (e) {
addError(e.toString(), 'crud().post');
return 'failure'; // Return a recognizable failure string for JSON errors
}
} else {
addError(
'Non-200 response code: ${response.statusCode}', 'crud().post');
return 'failure'; // Handle unexpected status codes as failures
}
} catch (e) {
addError('HTTP request error: $e', 'crud().post');
return 'failure'; // Handle HTTP request errors as failures
}
}
Future<dynamic> getTokenParent({
required String link,
Map<String, dynamic>? payload,
@@ -298,45 +340,6 @@ class CRUD {
// return response.statusCode;
// }
// }
Future<dynamic> post({
required String link,
Map<String, dynamic>? payload,
}) async {
var url = Uri.parse(link);
try {
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
},
);
if (response.statusCode == 200) {
try {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return jsonData;
} else {
return jsonData['status'];
}
} catch (e) {
addError(e.toString(), 'crud().post');
return 'failure'; // Return a recognizable failure string for JSON errors
}
} else {
addError(
'Non-200 response code: ${response.statusCode}', 'crud().post');
return 'failure'; // Handle unexpected status codes as failures
}
} catch (e) {
addError('HTTP request error: $e', 'crud().post');
return 'failure'; // Handle HTTP request errors as failures
}
}
Future<dynamic> postPayMob({
required String link,

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
String initializationVector = Env.initializationVector; // 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

@@ -1,64 +0,0 @@
// import 'dart:async';
// import 'package:background_location/background_location.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
// class LocationBackgroundController extends GetxController {
// @override
// void onInit() {
// super.onInit();
// requestLocationPermission();
// configureBackgroundLocation();
// }
// Future<void> requestLocationPermission() async {
// var status = await Permission.locationAlways.status;
// if (!status.isGranted) {
// await Permission.locationAlways.request();
// }
// }
// Future<void> configureBackgroundLocation() async {
// await BackgroundLocation.setAndroidNotification(
// title: "Background Location",
// message: "Tracking location...",
// icon: "@mipmap/ic_launcher",
// );
// BackgroundLocation.setAndroidConfiguration(1000);
// BackgroundLocation.startLocationService();
// BackgroundLocation.getLocationUpdates((location) {
// // Handle location updates here
// });
// }
// startBackLocation() async {
// Timer.periodic(const Duration(seconds: 5), (timer) {
// getBackgroundLocation();
// });
// }
// getBackgroundLocation() async {
// var status = await Permission.locationAlways.status;
// if (status.isGranted) {
// await BackgroundLocation.startLocationService(
// distanceFilter: 20, forceAndroidLocationManager: true);
// BackgroundLocation.setAndroidConfiguration(
// Duration.microsecondsPerSecond); // Set interval to 5 seconds
// BackgroundLocation.getLocationUpdates((location1) {
// Latitude: ${location1.latitude.toString()}
// Longitude: ${location1.longitude.toString()}
// Altitude: ${location1.altitude.toString()}
// Accuracy: ${location1.accuracy.toString()}
// Bearing: ${location1.bearing.toString()}
// Speed: ${location1.speed.toString()}
// ''');
// });
// } else {
// await Permission.locationAlways.request();
// }
// }
// }

View File

@@ -1,10 +1,13 @@
import 'dart:convert';
import 'package:SEFER/constant/box_name.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import 'crud.dart';
import 'encrypt_decrypt.dart';
class SecureStorage {
final FlutterSecureStorage _storage = const FlutterSecureStorage();
@@ -28,31 +31,47 @@ 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) {}
}
await getKey();
await getAIKey('FCM_PRIVATE_KEY');
}
Future<String?> getKey(String key) async {
getAIKey(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) {}
var d = jsonDecode(res)['message'];
storage.write(key: 'FCM_PRIVATE_KEY', value: d[key].toString());
// return d[key].toString();
} else {}
}
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.remove(BoxName.basicLink);
await box.remove(links[4]['name']);
await box.remove(links[1]['name']);
await box.remove(links[2]['name']);
await box.write(BoxName.locationName, links);
await box.write(BoxName.basicLink,
encryptionHelper.decryptData(links[0]['server_link']));
await box.write(links[2]['name'],
encryptionHelper.decryptData(links[2]['server_link']));
await box.write(links[1]['name'],
encryptionHelper.decryptData(links[1]['server_link']));
await box.write(BoxName.paymentLink,
encryptionHelper.decryptData(links[4]['server_link']));
}
} catch (e) {
print('Error fetching or decoding location data: $e');
}
return null;
}
}