Initial commit for service

This commit is contained in:
Hamza-Ayed
2026-01-20 23:36:57 +03:00
parent 66ae6c0ddb
commit ad2511bd96
34 changed files with 3757 additions and 4761 deletions

View File

@@ -17,35 +17,25 @@ import 'initilize.dart';
class CRUD {
var dev;
getJWT() async {
getJWT(String pass, email) async {
var dev = Platform.isAndroid ? 'android' : 'ios';
var payload = {
'password': AK.passnpassenger,
// 'email': box.read(BoxName.email),
'password': box.read(BoxName.password) ?? pass,
'email': box.read(BoxName.email) ?? email,
'aud': '${AK.allowed}$dev',
};
// if (box.read(BoxName.firstTimeLoadKey).toString() != 'false') {
var response0 = await http.post(
Uri.parse(AppLink.jwtService),
body: payload,
);
print(response0.body);
print(response0.request);
if (response0.statusCode == 200) {
final decodedResponse1 = jsonDecode(response0.body);
final jwt = decodedResponse1['jwt'];
Log.print('jwt: ${jwt}');
box.write(BoxName.jwt, X.c(X.c(X.c(jwt, cn), cC), cs));
// await AppInitializer().getAIKey(Service.keyOfApp);
// await AppInitializer().getAIKey(Service.initializationVector);
// await Future.delayed(Duration.zero);
await EncryptionHelper.initialize();
// await AppInitializer().getAIKey(Service.FCM_PRIVATE_KEY);
box.write(BoxName.firstTimeLoadKey, 'false');
// await AppInitializer().getKey();
} else {}
}
}
Future<dynamic> get({
@@ -61,7 +51,7 @@ class CRUD {
.split(AppInformation.addd)[0]);
if (isTokenExpired) {
await getJWT();
await getJWT(box.read(BoxName.password), box.read(BoxName.email));
}
var response = await http.post(
url,
@@ -72,10 +62,13 @@ class CRUD {
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
},
);
print(response.request);
Log.print('response.body: ${response.body}');
print(payload); // if (response.statusCode == 200) {
Log.print('esponse.body: ${response.body}');
Log.print('esponse.req: ${response.request}');
Log.print('payload: ${payload}');
var jsonData = jsonDecode(response.body);
Log.print('jsonData: ${jsonData}');
if (jsonData['status'] == 'success') {
return response.body;
}
@@ -179,7 +172,7 @@ class CRUD {
.split(AppInformation.addd)[0]);
if (isTokenExpired) {
await getJWT();
await getJWT(box.read(BoxName.password), box.read(BoxName.email));
}
var response = await http.post(
url,
@@ -190,10 +183,10 @@ class CRUD {
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
},
);
print(response.request);
Log.print('response.body: ${response.body}');
print(payload);
Log.print('req: ${response.request}');
Log.print('res: ${response.body}');
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {
if (jsonData['status'] == 'success') {
return response.body;

View File

@@ -15,19 +15,19 @@ import '../../print.dart';
class AppInitializer {
List<Map<String, dynamic>> links = [];
Future<void> initializeApp() async {
if (box.read(BoxName.jwt) == null) {
await CRUD().getJWT();
} else {
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 CRUD().getJWT();
}
}
}
// Future<void> initializeApp() async {
// if (box.read(BoxName.jwt) == null) {
// await CRUD().getJWT();
// } else {
// 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 CRUD().getJWT();
// }
// }
// }
getAIKey(String key1) async {
if (box.read(BoxName.firstTimeLoadKey) == null) {
@@ -35,7 +35,6 @@ class AppInitializer {
await CRUD().get(link: Env.getapiKey, payload: {"keyName": key1});
if (res != 'failure') {
var d = jsonDecode(res)['message'];
Log.print('d: ${d}');
await storage.write(key: key1, value: d[key1].toString());
await Future.delayed(Duration.zero);
} else {}