25-2/24/1
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import 'dart:convert';
|
||||
import 'package:Tripz/constant/box_name.dart';
|
||||
import 'package:Tripz/constant/links.dart';
|
||||
import 'package:Tripz/controller/auth/login_controller.dart';
|
||||
import 'package:Tripz/controller/functions/encrypt_decrypt.dart';
|
||||
import 'package:Tripz/controller/functions/package_info.dart';
|
||||
import 'package:Tripz/main.dart';
|
||||
import 'package:Tripz/views/widgets/mydialoug.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:Tripz/env/env.dart';
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
|
||||
import '../../constant/api_key.dart';
|
||||
|
||||
import '../../constant/char_map.dart';
|
||||
import '../../constant/info.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/widgets/elevated_btn.dart';
|
||||
import '../../views/widgets/error_snakbar.dart';
|
||||
import 'add_error.dart';
|
||||
import 'upload_image.dart';
|
||||
|
||||
@@ -27,25 +35,89 @@ class CRUD {
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
||||
// 'Bearer ${box.read(BoxName.firstTimeLoadKey) != null ? EncryptionHelper.instance.decryptData(box.read(BoxName.jwt).toString()) : box.read(BoxName.jwt).toString()}'
|
||||
// 'Bearer ${box.read(BoxName.jwt).toString()}'
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
},
|
||||
);
|
||||
// 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') {
|
||||
return response.body;
|
||||
}
|
||||
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') {
|
||||
return response.body;
|
||||
}
|
||||
|
||||
return jsonData['status'];
|
||||
return jsonData['status'];
|
||||
} else if (response.statusCode == 401) {
|
||||
// Specifically handle 401 Unauthorized
|
||||
var jsonData = jsonDecode(response.body);
|
||||
|
||||
if (jsonData['error'] == 'Token expired') {
|
||||
// Show snackbar prompting to re-login
|
||||
await Get.put(LoginController()).getJWT();
|
||||
mySnackbarSuccess('please order now'.tr);
|
||||
return 'token_expired'; // Return a specific value for token expiration
|
||||
} else {
|
||||
// Other 401 errors
|
||||
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
return 'failure';
|
||||
}
|
||||
} else {
|
||||
addError('Non-200 response code: ${response.statusCode}',
|
||||
'crud().post - Other');
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> post({
|
||||
Future<dynamic> getWallet({
|
||||
required String link,
|
||||
Map<String, dynamic>? payload,
|
||||
}) async {
|
||||
var s = await LoginController().getJwtWallet();
|
||||
var url = Uri.parse(
|
||||
link,
|
||||
);
|
||||
var response = await http.post(
|
||||
url,
|
||||
body: payload,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization': 'Bearer $s'
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
return response.body;
|
||||
}
|
||||
|
||||
return jsonData['status'];
|
||||
} else if (response.statusCode == 401) {
|
||||
// Specifically handle 401 Unauthorized
|
||||
var jsonData = jsonDecode(response.body);
|
||||
|
||||
if (jsonData['error'] == 'Token expired') {
|
||||
// Show snackbar prompting to re-login
|
||||
await Get.put(LoginController()).getJwtWallet();
|
||||
|
||||
return 'token_expired'; // Return a specific value for token expiration
|
||||
} else {
|
||||
// Other 401 errors
|
||||
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
return 'failure';
|
||||
}
|
||||
} else {
|
||||
addError('Non-200 response code: ${response.statusCode}',
|
||||
'crud().post - Other');
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> post(
|
||||
{required String link, Map<String, dynamic>? payload}) async {
|
||||
var url = Uri.parse(link);
|
||||
try {
|
||||
var response = await http.post(
|
||||
@@ -54,34 +126,56 @@ class CRUD {
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
|
||||
},
|
||||
);
|
||||
|
||||
// Log.print('req: ${response.request}');
|
||||
// Log.print('response: ${response.body}');
|
||||
// Log.print('payload: ${payload}');
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
// Log.print('req: ${response.request}');
|
||||
// Log.print('response: ${response.body}');
|
||||
// Log.print('payload: ${payload}');
|
||||
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
|
||||
addError(e.toString(), 'crud().post - JSON decoding');
|
||||
return 'failure';
|
||||
}
|
||||
} else if (response.statusCode == 401) {
|
||||
// Specifically handle 401 Unauthorized
|
||||
var jsonData = jsonDecode(response.body);
|
||||
|
||||
if (jsonData['error'] == 'Token expired') {
|
||||
// Show snackbar prompting to re-login
|
||||
await Get.put(LoginController()).getJWT();
|
||||
// MyDialog().getDialog(
|
||||
// 'Session expired. Please log in again.'.tr,
|
||||
// '',
|
||||
// () {
|
||||
// Get.put(LoginController()).loginUsingCredentials(
|
||||
// box.read(BoxName.passengerID), box.read(BoxName.email));
|
||||
// Get.back();
|
||||
// },
|
||||
// );
|
||||
|
||||
return 'token_expired'; // Return a specific value for token expiration
|
||||
} else {
|
||||
// Other 401 errors
|
||||
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
return 'failure';
|
||||
}
|
||||
} else {
|
||||
addError(
|
||||
'Non-200 response code: ${response.statusCode}', 'crud().post');
|
||||
return 'failure'; // Handle unexpected status codes as failures
|
||||
addError('Non-200 response code: ${response.statusCode}',
|
||||
'crud().post - Other');
|
||||
return 'failure';
|
||||
}
|
||||
} catch (e) {
|
||||
addError('HTTP request error: $e', 'crud().post');
|
||||
return 'failure'; // Handle HTTP request errors as failures
|
||||
addError('HTTP request error: $e', 'crud().post - HTTP');
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,24 +603,24 @@ class CRUD {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> update({
|
||||
required String endpoint,
|
||||
required Map<String, dynamic> data,
|
||||
required String id,
|
||||
}) async {
|
||||
// String? basicAuthCredentials =
|
||||
// await storage.read(key: BoxName.basicAuthCredentials);
|
||||
var url = Uri.parse('$endpoint/$id');
|
||||
var response = await http.put(
|
||||
url,
|
||||
body: json.encode(data),
|
||||
headers: {
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
||||
},
|
||||
);
|
||||
return json.decode(response.body);
|
||||
}
|
||||
// Future<dynamic> update({
|
||||
// required String endpoint,
|
||||
// required Map<String, dynamic> data,
|
||||
// required String id,
|
||||
// }) async {
|
||||
// // String? basicAuthCredentials =
|
||||
// // await storage.read(key: BoxName.basicAuthCredentials);
|
||||
// var url = Uri.parse('$endpoint/$id');
|
||||
// var response = await http.put(
|
||||
// url,
|
||||
// body: json.encode(data),
|
||||
// headers: {
|
||||
// 'Authorization':
|
||||
// 'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
||||
// },
|
||||
// );
|
||||
// return json.decode(response.body);
|
||||
// }
|
||||
|
||||
Future<dynamic> delete({
|
||||
required String endpoint,
|
||||
|
||||
@@ -1,90 +1,92 @@
|
||||
// import 'dart:io';
|
||||
//
|
||||
// import 'package:device_info_plus/device_info_plus.dart';
|
||||
//
|
||||
// class DeviceInfoPlus {
|
||||
// static List<Map<String, dynamic>> deviceDataList = [];
|
||||
//
|
||||
// static Future<List<Map<String, dynamic>>> getDeviceInfo() async {
|
||||
// final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||
//
|
||||
// try {
|
||||
// if (Platform.isAndroid) {
|
||||
// AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
|
||||
// Map<String, dynamic> deviceData = {
|
||||
// 'platform': 'Android',
|
||||
// 'brand': androidInfo.brand,
|
||||
// 'model': androidInfo.model,
|
||||
// 'androidId': androidInfo.device,
|
||||
// 'versionRelease': androidInfo.version.release,
|
||||
// 'sdkVersion': androidInfo.version.sdkInt,
|
||||
// 'manufacturer': androidInfo.manufacturer,
|
||||
// 'isPhysicalDevice': androidInfo.isPhysicalDevice,
|
||||
// 'serialNumber': androidInfo.serialNumber,
|
||||
// 'fingerprint': androidInfo.fingerprint,
|
||||
// 'type': androidInfo.type,
|
||||
// 'data': androidInfo.data,
|
||||
// 'version': androidInfo.version,
|
||||
// 'tags': androidInfo.tags,
|
||||
// 'display': androidInfo.display,
|
||||
// };
|
||||
// deviceDataList.add(deviceData);
|
||||
// } else if (Platform.isIOS) {
|
||||
// IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
|
||||
// Map<String, dynamic> deviceData = {
|
||||
// 'brand': 'Apple',
|
||||
// 'model': iosInfo.model,
|
||||
// 'systemName': iosInfo.systemName,
|
||||
// 'systemVersion': iosInfo.systemVersion,
|
||||
// 'utsname': iosInfo.utsname,
|
||||
// 'isPhysicalDevice': iosInfo.isPhysicalDevice,
|
||||
// 'identifierForVendor': iosInfo.identifierForVendor,
|
||||
// 'name': iosInfo.name,
|
||||
// 'localizedModel': iosInfo.localizedModel,
|
||||
// };
|
||||
// deviceDataList.add(deviceData);
|
||||
// } else if (Platform.isMacOS) {
|
||||
// MacOsDeviceInfo macInfo = await deviceInfoPlugin.macOsInfo;
|
||||
// Map<String, dynamic> deviceData = {
|
||||
// 'platform': 'macOS',
|
||||
// 'model': macInfo.model,
|
||||
// 'version': macInfo.systemGUID,
|
||||
// };
|
||||
// deviceDataList.add(deviceData);
|
||||
// } else if (Platform.isWindows) {
|
||||
// WindowsDeviceInfo windowsInfo = await deviceInfoPlugin.windowsInfo;
|
||||
// Map<String, dynamic> deviceData = {
|
||||
// 'platform': 'Windows',
|
||||
// 'manufacturer': windowsInfo.computerName,
|
||||
// 'version': windowsInfo.majorVersion,
|
||||
// 'deviceId': windowsInfo.deviceId,
|
||||
// 'userName': windowsInfo.userName,
|
||||
// 'productName': windowsInfo.productName,
|
||||
// 'installDate': windowsInfo.installDate,
|
||||
// 'productId': windowsInfo.productId,
|
||||
// 'numberOfCores': windowsInfo.numberOfCores,
|
||||
// 'systemMemoryInMegabytes': windowsInfo.systemMemoryInMegabytes,
|
||||
// };
|
||||
// deviceDataList.add(deviceData);
|
||||
// } else if (Platform.isLinux) {
|
||||
// LinuxDeviceInfo linuxInfo = await deviceInfoPlugin.linuxInfo;
|
||||
// Map<String, dynamic> deviceData = {
|
||||
// 'platform': 'Linux',
|
||||
// 'manufacturer': linuxInfo.name,
|
||||
// 'version': linuxInfo.version,
|
||||
// };
|
||||
// deviceDataList.add(deviceData);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// }
|
||||
//
|
||||
// return deviceDataList;
|
||||
// }
|
||||
//
|
||||
// // Method to print all device data
|
||||
// static void printDeviceInfo() {
|
||||
// for (Map<String, dynamic> deviceData in deviceDataList) {
|
||||
// 'Version: ${deviceData['version'] ?? deviceData['versionRelease'] ?? 'N/A'}');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
|
||||
import '../../print.dart';
|
||||
|
||||
class DeviceInfoPlus {
|
||||
static List<Map<String, dynamic>> deviceDataList = [];
|
||||
|
||||
static Future<List<Map<String, dynamic>>> getDeviceInfo() async {
|
||||
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||
|
||||
try {
|
||||
if (Platform.isAndroid) {
|
||||
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
|
||||
Map<String, dynamic> deviceData = {
|
||||
'platform': 'Android',
|
||||
'brand': androidInfo.brand,
|
||||
'model': androidInfo.model,
|
||||
'androidId': androidInfo.device,
|
||||
'versionRelease': androidInfo.version.release,
|
||||
'sdkVersion': androidInfo.version.sdkInt,
|
||||
'manufacturer': androidInfo.manufacturer,
|
||||
'isPhysicalDevice': androidInfo.isPhysicalDevice,
|
||||
'serialNumber': androidInfo.serialNumber,
|
||||
'fingerprint': androidInfo.fingerprint,
|
||||
'type': androidInfo.type,
|
||||
'data': androidInfo.data,
|
||||
'version': androidInfo.version,
|
||||
'tags': androidInfo.tags,
|
||||
'display': androidInfo.display,
|
||||
};
|
||||
// Log.print('deviceData: ${deviceData}');
|
||||
deviceDataList.add(deviceData);
|
||||
} else if (Platform.isIOS) {
|
||||
IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
|
||||
Map<String, dynamic> deviceData = {
|
||||
'brand': 'Apple',
|
||||
'model': iosInfo.model,
|
||||
'systemName': iosInfo.systemName,
|
||||
'systemVersion': iosInfo.systemVersion,
|
||||
'utsname': iosInfo.utsname,
|
||||
'isPhysicalDevice': iosInfo.isPhysicalDevice,
|
||||
'identifierForVendor': iosInfo.identifierForVendor,
|
||||
'name': iosInfo.name,
|
||||
'localizedModel': iosInfo.localizedModel,
|
||||
};
|
||||
deviceDataList.add(deviceData);
|
||||
} else if (Platform.isMacOS) {
|
||||
MacOsDeviceInfo macInfo = await deviceInfoPlugin.macOsInfo;
|
||||
Map<String, dynamic> deviceData = {
|
||||
'platform': 'macOS',
|
||||
'model': macInfo.model,
|
||||
'version': macInfo.systemGUID,
|
||||
};
|
||||
deviceDataList.add(deviceData);
|
||||
} else if (Platform.isWindows) {
|
||||
WindowsDeviceInfo windowsInfo = await deviceInfoPlugin.windowsInfo;
|
||||
Map<String, dynamic> deviceData = {
|
||||
'platform': 'Windows',
|
||||
'manufacturer': windowsInfo.computerName,
|
||||
'version': windowsInfo.majorVersion,
|
||||
'deviceId': windowsInfo.deviceId,
|
||||
'userName': windowsInfo.userName,
|
||||
'productName': windowsInfo.productName,
|
||||
'installDate': windowsInfo.installDate,
|
||||
'productId': windowsInfo.productId,
|
||||
'numberOfCores': windowsInfo.numberOfCores,
|
||||
'systemMemoryInMegabytes': windowsInfo.systemMemoryInMegabytes,
|
||||
};
|
||||
deviceDataList.add(deviceData);
|
||||
} else if (Platform.isLinux) {
|
||||
LinuxDeviceInfo linuxInfo = await deviceInfoPlugin.linuxInfo;
|
||||
Map<String, dynamic> deviceData = {
|
||||
'platform': 'Linux',
|
||||
'manufacturer': linuxInfo.name,
|
||||
'version': linuxInfo.version,
|
||||
};
|
||||
deviceDataList.add(deviceData);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return deviceDataList;
|
||||
}
|
||||
|
||||
// Method to print all device data
|
||||
static void printDeviceInfo() {
|
||||
for (Map<String, dynamic> deviceData in deviceDataList) {
|
||||
'Version: ${deviceData['version'] ?? deviceData['versionRelease'] ?? 'N/A'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,51 @@
|
||||
import 'package:Tripz/constant/box_name.dart';
|
||||
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,
|
||||
);
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class EncryptionHelper {
|
||||
final encrypt.Key key;
|
||||
final encrypt.IV iv;
|
||||
static EncryptionHelper? _instance;
|
||||
|
||||
EncryptionHelper(
|
||||
{required String secretKey, required String initializationVector})
|
||||
: key = encrypt.Key.fromUtf8(secretKey),
|
||||
iv = encrypt.IV.fromUtf8(initializationVector);
|
||||
late final encrypt.Key key;
|
||||
late final encrypt.IV iv;
|
||||
|
||||
// Initialize the helper
|
||||
EncryptionHelper._(this.key, this.iv);
|
||||
static EncryptionHelper get instance {
|
||||
if (_instance == null) {
|
||||
throw Exception(
|
||||
"EncryptionHelper is not initialized. Call `await EncryptionHelper.initialize()` in main.");
|
||||
}
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
/// Encrypts the given plain text
|
||||
/// Initializes and stores the instance globally
|
||||
static Future<void> initialize() async {
|
||||
if (_instance != null) {
|
||||
debugPrint("EncryptionHelper is already initialized.");
|
||||
return; // Prevent re-initialization
|
||||
}
|
||||
debugPrint("Initializing EncryptionHelper...");
|
||||
// Read stored keys
|
||||
String? keyOfApp = await storage.read(key: BoxName.keyOfApp);
|
||||
// Log.print('keyOfApp: ${keyOfApp}');
|
||||
String? initializationVector =
|
||||
await storage.read(key: BoxName.initializationVector);
|
||||
// Log.print('initializationVector: ${initializationVector}');
|
||||
// Set the global instance
|
||||
_instance = EncryptionHelper._(
|
||||
encrypt.Key.fromUtf8(keyOfApp!),
|
||||
encrypt.IV.fromUtf8(initializationVector!),
|
||||
);
|
||||
debugPrint("EncryptionHelper initialized successfully.");
|
||||
}
|
||||
|
||||
/// Encrypts a string
|
||||
String encryptData(String plainText) {
|
||||
try {
|
||||
final encrypter = encrypt.Encrypter(encrypt.AES(key,
|
||||
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
|
||||
final encrypter =
|
||||
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
|
||||
final encrypted = encrypter.encrypt(plainText, iv: iv);
|
||||
return encrypted.base64;
|
||||
} catch (e) {
|
||||
@@ -36,14 +54,13 @@ class EncryptionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/// Decrypts the given encrypted text
|
||||
/// Decrypts a string
|
||||
String decryptData(String encryptedText) {
|
||||
try {
|
||||
final encrypter = encrypt.Encrypter(encrypt.AES(key,
|
||||
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
|
||||
final encrypter =
|
||||
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
|
||||
final encrypted = encrypt.Encrypted.fromBase64(encryptedText);
|
||||
final decrypted = encrypter.decrypt(encrypted, iv: iv);
|
||||
return decrypted;
|
||||
return encrypter.decrypt(encrypted, iv: iv);
|
||||
} catch (e) {
|
||||
debugPrint('Decryption Error: $e');
|
||||
return '';
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/colors.dart';
|
||||
import '../../main.dart';
|
||||
import 'encrypt_decrypt.dart';
|
||||
|
||||
Future<void> checkForUpdate(BuildContext context) async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
@@ -38,6 +40,24 @@ checkForBounusInvitation() {
|
||||
// }
|
||||
// return '';
|
||||
// }
|
||||
getDeviceFingerprint() async {
|
||||
final deviceInfo = await DeviceInfoPlugin().deviceInfo;
|
||||
var deviceData;
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
deviceData = deviceInfo.data;
|
||||
} else if (Platform.isIOS) {
|
||||
deviceData = deviceInfo.data;
|
||||
}
|
||||
|
||||
final String deviceId =
|
||||
deviceData['androidId'] ?? deviceData['identifierForVendor'];
|
||||
final String deviceModel = deviceData['model'];
|
||||
final String osVersion = deviceData['systemVersion'];
|
||||
|
||||
return EncryptionHelper.instance
|
||||
.encryptData('${deviceId}_${deviceModel}_$osVersion');
|
||||
}
|
||||
|
||||
void showUpdateDialog(BuildContext context) {
|
||||
final String storeUrl = Platform.isAndroid
|
||||
@@ -158,3 +178,103 @@ void showUpdateDialog(BuildContext context) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class SecurityHelper {
|
||||
/// Performs security checks and handles potential risks
|
||||
static Future<void> performSecurityChecks() async {
|
||||
bool isNotTrust = false;
|
||||
bool isJailBroken = false;
|
||||
bool isRealDevice = true;
|
||||
bool isOnExternalStorage = false;
|
||||
bool checkForIssues = false;
|
||||
bool isDevMode = false;
|
||||
bool isTampered = false;
|
||||
String bundleId = "";
|
||||
|
||||
try {
|
||||
isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
|
||||
isJailBroken = await JailbreakRootDetection.instance.isJailBroken;
|
||||
isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
|
||||
isOnExternalStorage =
|
||||
await JailbreakRootDetection.instance.isOnExternalStorage;
|
||||
|
||||
List<JailbreakIssue> issues =
|
||||
await JailbreakRootDetection.instance.checkForIssues;
|
||||
checkForIssues = issues.isNotEmpty;
|
||||
|
||||
isDevMode = await JailbreakRootDetection.instance.isDevMode;
|
||||
|
||||
// Get Bundle ID
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
bundleId = packageInfo.packageName;
|
||||
if (bundleId.isNotEmpty) {
|
||||
// Pass the CORRECT bundle ID to isTampered
|
||||
isTampered = await JailbreakRootDetection.instance.isTampered(bundleId);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("Error during security checks: $e");
|
||||
// Consider handling specific exceptions, not just general errors.
|
||||
}
|
||||
|
||||
// Save values to storage (using GetStorage)
|
||||
await box.write('isNotTrust', isNotTrust); // Use await for write operations
|
||||
await box.write('isTampered', isTampered); // Use await
|
||||
await box.write('isJailBroken', isJailBroken); // Use await
|
||||
|
||||
// debugPrint("Security Check Results:");
|
||||
// debugPrint("isNotTrust: $isNotTrust");
|
||||
// debugPrint("isJailBroken: $isJailBroken");
|
||||
// debugPrint("isRealDevice: $isRealDevice");
|
||||
// debugPrint("isOnExternalStorage: $isOnExternalStorage");
|
||||
// debugPrint("checkForIssues: $checkForIssues");
|
||||
// debugPrint("isDevMode: $isDevMode");
|
||||
// debugPrint("isTampered: $isTampered");
|
||||
// debugPrint("Bundle ID: $bundleId"); // Print the bundle ID
|
||||
|
||||
// Check for security risks and potentially show a warning
|
||||
if (isNotTrust ||
|
||||
isJailBroken ||
|
||||
isTampered ||
|
||||
isDevMode ||
|
||||
isOnExternalStorage ||
|
||||
!isRealDevice) {
|
||||
// print("security_warning".tr); //using easy_localization
|
||||
// Use a more robust approach to show a warning, like a dialog:
|
||||
_showSecurityWarning();
|
||||
}
|
||||
}
|
||||
|
||||
/// Deletes all app data
|
||||
static Future<void> clearAllData() async {
|
||||
//await storage.deleteAll(); // What's 'storage'? Be specific. Likely GetStorage as well.
|
||||
await box.erase(); // Clear GetStorage data
|
||||
exit(0); // This will terminate the app. Be VERY careful with this.
|
||||
}
|
||||
|
||||
static void _showSecurityWarning() {
|
||||
// Show a dialog, navigate to an error screen, etc.
|
||||
// Example using Get.dialog (if you use GetX):
|
||||
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text("Security Warning".tr), // Or use localized string
|
||||
content: Text(
|
||||
"Potential security risks detected. The application may not function correctly."
|
||||
.tr), //Or use localized string
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await storage.deleteAll();
|
||||
await box.erase();
|
||||
Get.back(); // Close the dialog
|
||||
// Or, if you really must, exit the app (but give the user a chance!)
|
||||
exit(0);
|
||||
},
|
||||
child: Text("OK"), // Or use a localized string
|
||||
),
|
||||
],
|
||||
),
|
||||
barrierDismissible: false, // Prevent closing by tapping outside
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:Tripz/constant/box_name.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:Tripz/constant/info.dart';
|
||||
import 'package:Tripz/controller/auth/login_controller.dart';
|
||||
import 'package:jwt_decoder/jwt_decoder.dart';
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
|
||||
import '../../constant/char_map.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
@@ -10,15 +14,13 @@ import 'crud.dart';
|
||||
import 'encrypt_decrypt.dart';
|
||||
|
||||
class SecureStorage {
|
||||
final FlutterSecureStorage _storage = const FlutterSecureStorage();
|
||||
|
||||
void saveData(String key, value) async {
|
||||
await _storage.write(key: key, value: value);
|
||||
await storage.write(key: key, value: value);
|
||||
}
|
||||
|
||||
Future<String?> readData(String boxName) async {
|
||||
final String? value = await _storage.read(key: boxName);
|
||||
return value;
|
||||
final String? value = await storage.read(key: boxName);
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,18 +36,33 @@ class AppInitializer {
|
||||
List<Map<String, dynamic>> links = [];
|
||||
|
||||
Future<void> initializeApp() async {
|
||||
await getKey();
|
||||
// await getAIKey('FCM_PRIVATE_KEY');
|
||||
// Log.print('box.read("jwt"): ${box.read(BoxName.jwt)}');
|
||||
if (box.read(BoxName.jwt) == null) {
|
||||
await LoginController().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 LoginController().getJWT();
|
||||
}
|
||||
}
|
||||
|
||||
// await getKey();
|
||||
}
|
||||
|
||||
getAIKey(String key) async {
|
||||
var res =
|
||||
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
|
||||
if (res != 'failure') {
|
||||
var d = jsonDecode(res)['message'];
|
||||
storage.write(key: 'FCM_PRIVATE_KEY', value: d[key].toString());
|
||||
// return d[key].toString();
|
||||
} else {}
|
||||
getAIKey(String key1) async {
|
||||
if (box.read(BoxName.firstTimeLoadKey) == null) {
|
||||
var res =
|
||||
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key1});
|
||||
if (res != 'failure') {
|
||||
var d = jsonDecode(res)['message'];
|
||||
storage.write(key: key1, value: d[key1].toString());
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getKey() async {
|
||||
@@ -62,13 +79,15 @@ class AppInitializer {
|
||||
await box.remove(links[2]['name']);
|
||||
await box.write(BoxName.locationName, links);
|
||||
await box.write(BoxName.basicLink,
|
||||
encryptionHelper.decryptData(links[0]['server_link']));
|
||||
EncryptionHelper.instance.decryptData(links[0]['server_link']));
|
||||
await box.write(links[2]['name'],
|
||||
encryptionHelper.decryptData(links[2]['server_link']));
|
||||
EncryptionHelper.instance.decryptData(links[2]['server_link']));
|
||||
await box.write(links[1]['name'],
|
||||
encryptionHelper.decryptData(links[1]['server_link']));
|
||||
EncryptionHelper.instance.decryptData(links[3]['server_link']));
|
||||
await box.write(links[3]['name'],
|
||||
EncryptionHelper.instance.decryptData(links[1]['server_link']));
|
||||
await box.write(BoxName.paymentLink,
|
||||
encryptionHelper.decryptData(links[4]['server_link']));
|
||||
EncryptionHelper.instance.decryptData(links[4]['server_link']));
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching or decoding location data: $e');
|
||||
|
||||
18
lib/controller/functions/sss.dart
Normal file
18
lib/controller/functions/sss.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
|
||||
import '../../constant/char_map.dart';
|
||||
import '../../main.dart';
|
||||
|
||||
class Sss {
|
||||
static read(String boxname) async {
|
||||
return box.read(X.r(X.r(X.r(boxname, cn), cC), cs));
|
||||
}
|
||||
|
||||
static write(String boxname, value) async {
|
||||
return box.write(boxname, X.c(X.c(X.c(value, cn), cC), cs));
|
||||
}
|
||||
|
||||
static delete(String boxname) async {
|
||||
return box.remove(boxname);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/char_map.dart';
|
||||
import '../../constant/colors.dart';
|
||||
import '../../constant/info.dart';
|
||||
import '../../main.dart';
|
||||
|
||||
class ImageController extends GetxController {
|
||||
@@ -75,7 +78,7 @@ class ImageController extends GetxController {
|
||||
);
|
||||
request.headers.addAll({
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
});
|
||||
// Set the file name to the driverID
|
||||
request.files.add(
|
||||
|
||||
Reference in New Issue
Block a user