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.
doctor_app_flutter/lib/providers/auth_provider.dart

186 lines
5.3 KiB
Dart

4 years ago
import 'package:doctor_app_flutter/client/base_app_client.dart';
4 years ago
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:flutter/cupertino.dart';
4 years ago
4 years ago
import '../models/doctor/user_model.dart';
const LOGIN_URL = 'Services/Sentry.svc/REST/MemberLogIN_New';
const INSERT_DEVICE_IMEI =
'Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI';
5 years ago
const SELECT_DEVICE_IMEI =
'Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI';
5 years ago
const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE =
'Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType';
4 years ago
const MEMBER_CHECK_ACTIVATION_CODE_NEW =
'Services/Sentry.svc/REST/MemberCheckActivationCode_New';
const GET_DOC_PROFILES = 'Services/Doctors.svc/REST/GetDocProfiles';
4 years ago
const GET_CLINICS_FOR_DOCTOR =
'Services/DoctorApplication.svc/REST/GetClinicsForDoctor';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
4 years ago
class AuthProvider with ChangeNotifier {
List<ClinicModel> doctorsClinicList = [];
String selectedClinicName;
bool isLogin = false;
bool isLoading = true;
AuthProvider() {
getUserAuthentication();
}
void getUserAuthentication() async {
Map profile = await sharedPref.getObj(DOCTOR_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;
}
}
}
4 years ago
Future<dynamic> login(UserModel userInfo) async {
try {
4 years ago
dynamic localRes;
await BaseAppClient.post(LOGIN_URL,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
}, onFailure: (String error, int statusCode) {
throw error;
}, body: {
"UserID": userInfo.UserID,
"Password": userInfo.Password,
"ProjectID": userInfo.ProjectID,
"LanguageID": userInfo.LanguageID,
"IPAdress": userInfo.IPAdress,
"VersionID": userInfo.VersionID,
"Channel": userInfo.Channel,
"SessionID": userInfo.SessionID
});
4 years ago
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
4 years ago
Future<dynamic> insertDeviceImei(imei) async {
try {
4 years ago
dynamic localRes;
await BaseAppClient.post(INSERT_DEVICE_IMEI,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
}, onFailure: (String error, int statusCode) {
throw error;
}, body: imei);
4 years ago
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
4 years ago
Future<dynamic> selectDeviceImei(imei) async {
try {
4 years ago
dynamic localRes;
await BaseAppClient.post(SELECT_DEVICE_IMEI,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
}, onFailure: (String error, int statusCode) {
throw error;
}, body: imei);
4 years ago
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
Future sendActivationCodeByOtpNotificationType(activationCodeModel) async {
try {
4 years ago
var localRes;
await BaseAppClient.post(SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
}, onFailure: (String error, int statusCode) {
throw error;
}, body: activationCodeModel);
4 years ago
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
4 years ago
Future<dynamic> memberCheckActivationCodeNew(activationCodeModel) async {
try {
4 years ago
dynamic localRes;
await BaseAppClient.post(MEMBER_CHECK_ACTIVATION_CODE_NEW,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
selectedClinicName =
ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName;
notifyListeners();
response['List_DoctorsClinic'].forEach((v) {
doctorsClinicList.add(new ClinicModel.fromJson(v));
});
}, onFailure: (String error, int statusCode) {
throw error;
}, body: activationCodeModel);
4 years ago
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
4 years ago
/*
*@author: Elham Rababah
*@Date:17/5/2020
*@param: docInfo
*@return:Future<Map>
*@desc: getDocProfiles
*/
4 years ago
Future<dynamic> getDocProfiles(docInfo) async {
try {
4 years ago
dynamic localRes;
await BaseAppClient.post(GET_DOC_PROFILES,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
//ClinicDescription
4 years ago
selectedClinicName =
response['DoctorProfileList'][0]['ClinicDescription'];
}, onFailure: (String error, int statusCode) {
throw error;
}, body: docInfo);
4 years ago
notifyListeners();
4 years ago
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
}