You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
4.6 KiB
Dart
151 lines
4.6 KiB
Dart
import 'package:diplomaticquarterapp/config/config.dart';
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_request.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_response.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart';
|
|
import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
// SharedPreferences sharedPref = new SharedPreferences();
|
|
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
|
|
AppSharedPreferences sharedPref = new AppSharedPreferences();
|
|
|
|
const String INSERT_DEVICE_IMEI = '/Patients.svc/REST/Patient_INSERTDeviceIMEI';
|
|
const String SELECT_DEVICE_IMEI =
|
|
'/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI';
|
|
const String CHECK_PATIENT_AUTH =
|
|
'/Authentication.svc/REST/CheckPatientAuthentication';
|
|
const GET_MOBILE_INFO = '/Authentication.svc/REST/GetMobileLoginInfo';
|
|
|
|
class AuthProvider with ChangeNotifier {
|
|
bool isLogin = false;
|
|
bool isLoading = true;
|
|
AuthProvider() {
|
|
getUserAuthentication();
|
|
}
|
|
|
|
void getUserAuthentication() async {
|
|
Map profile = await sharedPref.getObject(USER_PROFILE);
|
|
if (profile != null) {
|
|
isLoading = false;
|
|
isLogin = true;
|
|
} else {
|
|
isLoading = false;
|
|
isLogin = false;
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
APP_STATUS get stutas {
|
|
if (isLoading) {
|
|
return APP_STATUS.LOADING;
|
|
} else {
|
|
if (this.isLogin) {
|
|
return APP_STATUS.AUTHENTICATED;
|
|
} else {
|
|
return APP_STATUS.UNAUTHENTICATED;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Future<dynamic> login(UserModel userInfo) async {
|
|
// try {
|
|
// dynamic localRes;
|
|
|
|
// await BaseAppClient.post(LOGIN_URL,
|
|
// onSuccess: (dynamic response, int statusCode) {
|
|
// localRes = response;
|
|
// }, onFailure: (String error, int statusCode) {
|
|
// throw error;
|
|
// }, body: userInfo.toJson());
|
|
|
|
// return Future.value(localRes);
|
|
// } catch (error) {
|
|
// print(error);
|
|
// throw error;
|
|
// }
|
|
// }
|
|
|
|
Future<dynamic> insertDeviceImei(imei) async {
|
|
try {
|
|
dynamic localRes;
|
|
|
|
await new BaseAppClient().post(INSERT_DEVICE_IMEI,
|
|
onSuccess: (dynamic response, int statusCode) {
|
|
localRes = response;
|
|
}, onFailure: (String error, int statusCode) {
|
|
throw error;
|
|
}, body: imei);
|
|
return Future.value(localRes);
|
|
} catch (error) {
|
|
print(error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
Future<SelectDeviceIMEIRES> selectDeviceImei(imei) async {
|
|
try {
|
|
dynamic localRes;
|
|
await new BaseAppClient().post(SELECT_DEVICE_IMEI,
|
|
onSuccess: (dynamic response, int statusCode) {
|
|
localRes = response;
|
|
}, onFailure: (String error, int statusCode) {
|
|
throw error;
|
|
}, body: imei);
|
|
return Future.value(localRes);
|
|
} catch (error) {
|
|
print(error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
Future<dynamic> checkPatientAuthentication(
|
|
CheckPatientAuthenticationReq request) async {
|
|
request.versionID = VERSION_ID;
|
|
request.channel = CHANNEL;
|
|
request.iPAdress = IP_ADDRESS;
|
|
request.generalid = GENERAL_ID;
|
|
request.languageID = 2;
|
|
request.patientOutSA = request.zipCode == '966' ? 0 : 1;
|
|
try {
|
|
dynamic localRes;
|
|
await new BaseAppClient().post(CHECK_PATIENT_AUTH,
|
|
onSuccess: (dynamic response, int statusCode) {
|
|
localRes = response;
|
|
}, onFailure: (String error, int statusCode) {
|
|
throw error;
|
|
}, body: request.toJson());
|
|
return Future.value(localRes);
|
|
} catch (error) {
|
|
print(error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
Future<GetMobileLoginInfoResponse> getLoginInfo(
|
|
GetMobileLoginInfoRequest request) async {
|
|
request.versionID = VERSION_ID;
|
|
request.channel = CHANNEL;
|
|
request.iPAdress = IP_ADDRESS;
|
|
request.generalid = GENERAL_ID;
|
|
request.languageID = 2;
|
|
request.patientOutSA = request.zipCode == '966' ? 0 : 1;
|
|
try {
|
|
dynamic localRes;
|
|
await new BaseAppClient().post(GET_MOBILE_INFO,
|
|
onSuccess: (dynamic response, int statusCode) {
|
|
localRes = response;
|
|
}, onFailure: (String error, int statusCode) {
|
|
throw error;
|
|
}, body: request.toJson());
|
|
return Future.value(localRes);
|
|
} catch (error) {
|
|
print(error);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|