|
|
|
|
@ -70,35 +70,25 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
bool isLogin = false;
|
|
|
|
|
bool unverified = false;
|
|
|
|
|
bool isFromLogin = false;
|
|
|
|
|
APP_STATUS app_status = APP_STATUS.LOADING;
|
|
|
|
|
|
|
|
|
|
APP_STATUS appStatus = APP_STATUS.LOADING;
|
|
|
|
|
String localToken ="";
|
|
|
|
|
AuthenticationViewModel({bool checkDeviceInfo = false}) {
|
|
|
|
|
getDeviceInfoFromFirebase();
|
|
|
|
|
getDoctorProfile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// select Device IMEI
|
|
|
|
|
Future selectDeviceImei(imei) async {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
await _authService.selectDeviceImei(imei);
|
|
|
|
|
if (_authService.hasError) {
|
|
|
|
|
error = _authService.error;
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
} else
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Insert Device IMEI
|
|
|
|
|
Future insertDeviceImei() async {
|
|
|
|
|
Future insertDeviceImei(token) async {
|
|
|
|
|
var loggedIn = await sharedPref.getObj(LOGGED_IN_USER);
|
|
|
|
|
var user = await sharedPref.getObj(LAST_LOGIN_USER);
|
|
|
|
|
if (user != null) {
|
|
|
|
|
user = GetIMEIDetailsModel.fromJson(user);
|
|
|
|
|
var data = await sharedPref.getObj(LAST_LOGIN_USER);
|
|
|
|
|
if (data != null) {
|
|
|
|
|
user = GetIMEIDetailsModel.fromJson(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var profileInfo = await sharedPref.getObj(DOCTOR_PROFILE);
|
|
|
|
|
|
|
|
|
|
profileInfo['IMEI'] = DEVICE_TOKEN;
|
|
|
|
|
profileInfo['IMEI'] = token;
|
|
|
|
|
profileInfo['LogInTypeID'] = await sharedPref.getInt(OTP_TYPE);
|
|
|
|
|
profileInfo['BioMetricEnabled'] = true;
|
|
|
|
|
profileInfo['MobileNo'] =
|
|
|
|
|
@ -115,9 +105,8 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
: user.doctorID;
|
|
|
|
|
insertIMEIDetailsModel.outSA = loggedIn != null ? loggedIn['PatientOutSA'] : user.outSA;
|
|
|
|
|
insertIMEIDetailsModel.vidaAuthTokenID = await sharedPref.getString(VIDA_AUTH_TOKEN_ID);
|
|
|
|
|
insertIMEIDetailsModel.vidaRefreshTokenID =
|
|
|
|
|
await sharedPref.getString(VIDA_REFRESH_TOKEN_ID);
|
|
|
|
|
insertIMEIDetailsModel.password = await sharedPref.getString(PASSWORD);
|
|
|
|
|
insertIMEIDetailsModel.vidaRefreshTokenID =await sharedPref.getString(VIDA_REFRESH_TOKEN_ID);
|
|
|
|
|
insertIMEIDetailsModel.password = userInfo.password;
|
|
|
|
|
|
|
|
|
|
await _authService.insertDeviceImei(insertIMEIDetailsModel);
|
|
|
|
|
if (_authService.hasError) {
|
|
|
|
|
@ -174,21 +163,22 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
ActivationCodeModel activationCodeModel = ActivationCodeModel(
|
|
|
|
|
facilityId: projectID,
|
|
|
|
|
memberID: loggedUser.listMemberInformation[0].memberID,
|
|
|
|
|
zipCode: loggedUser.zipCode,
|
|
|
|
|
mobileNumber: loggedUser.mobileNumber,
|
|
|
|
|
otpSendType: authMethodType.getTypeIdService().toString(),
|
|
|
|
|
password: password);
|
|
|
|
|
);
|
|
|
|
|
await _authService.sendActivationCodeForDoctorApp(activationCodeModel);
|
|
|
|
|
if (_authService.hasError) {
|
|
|
|
|
error = _authService.error;
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
} else
|
|
|
|
|
} else {
|
|
|
|
|
await sharedPref.setString(LOGIN_TOKEN_ID,
|
|
|
|
|
_authService.activationCodeForDoctorAppRes.logInTokenID);
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// check activation code for sms and whats app
|
|
|
|
|
Future checkActivationCodeForDoctorApp({String activationCode}) async {
|
|
|
|
|
Future checkActivationCodeForDoctorApp({String activationCode,bool isSilentLogin = false}) async {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
CheckActivationCodeRequestModel checkActivationCodeForDoctorApp =
|
|
|
|
|
new CheckActivationCodeRequestModel(
|
|
|
|
|
@ -201,13 +191,19 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
: user.projectID,
|
|
|
|
|
logInTokenID: await sharedPref.getString(LOGIN_TOKEN_ID),
|
|
|
|
|
activationCode: activationCode ?? '0000',
|
|
|
|
|
memberID:userInfo.userID!=null? int.parse(userInfo.userID):user.doctorID ,
|
|
|
|
|
password: userInfo.password,
|
|
|
|
|
facilityId:userInfo.projectID!=null? userInfo.projectID.toString():user.projectID.toString(),
|
|
|
|
|
oTPSendType: await sharedPref.getInt(OTP_TYPE),
|
|
|
|
|
iMEI: localToken,
|
|
|
|
|
isForSilentLogin:isSilentLogin,
|
|
|
|
|
generalid: "Cs2020@2016\$2958");
|
|
|
|
|
await _authService.checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp);
|
|
|
|
|
if (_authService.hasError) {
|
|
|
|
|
error = _authService.error;
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
} else {
|
|
|
|
|
await setDataAfterSendActivationSuccess(checkActivationCodeForDoctorAppRes);
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -253,15 +249,14 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// add token to shared preferences in case of send activation code is success
|
|
|
|
|
setDataAfterSendActivationSuccess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) {
|
|
|
|
|
print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode);
|
|
|
|
|
// DrAppToastMsg.showSuccesToast("_VerificationCode_ : " + sendActivationCodeForDoctorAppResponseModel.verificationCode);
|
|
|
|
|
sharedPref.setString(VIDA_AUTH_TOKEN_ID,
|
|
|
|
|
setDataAfterSendActivationSuccess(CheckActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel)async {
|
|
|
|
|
// print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode);
|
|
|
|
|
await sharedPref.setString(VIDA_AUTH_TOKEN_ID,
|
|
|
|
|
sendActivationCodeForDoctorAppResponseModel.vidaAuthTokenID);
|
|
|
|
|
sharedPref.setString(VIDA_REFRESH_TOKEN_ID,
|
|
|
|
|
await sharedPref.setString(VIDA_REFRESH_TOKEN_ID,
|
|
|
|
|
sendActivationCodeForDoctorAppResponseModel.vidaRefreshTokenID);
|
|
|
|
|
sharedPref.setString(LOGIN_TOKEN_ID,
|
|
|
|
|
sendActivationCodeForDoctorAppResponseModel.logInTokenID);
|
|
|
|
|
await sharedPref.setString(LOGIN_TOKEN_ID,
|
|
|
|
|
sendActivationCodeForDoctorAppResponseModel.authenticationTokenID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveObjToString(String key, value) async {
|
|
|
|
|
@ -312,7 +307,7 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// add some logic in case of check activation code is success
|
|
|
|
|
onCheckActivationCodeSuccess() async {
|
|
|
|
|
onCheckActivationCodeSuccess({bool isSilentLogin = false}) async {
|
|
|
|
|
sharedPref.setString(
|
|
|
|
|
TOKEN,
|
|
|
|
|
checkActivationCodeForDoctorAppRes.authenticationTokenID);
|
|
|
|
|
@ -359,17 +354,12 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
_firebaseMessaging.requestNotificationPermissions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Helpers.showErrorToast("fdfdfdfdf"+e.toString());
|
|
|
|
|
}
|
|
|
|
|
var token = await _firebaseMessaging.getToken();
|
|
|
|
|
if (DEVICE_TOKEN == "") {
|
|
|
|
|
DEVICE_TOKEN = token;
|
|
|
|
|
if (localToken == "") {
|
|
|
|
|
localToken = token;
|
|
|
|
|
|
|
|
|
|
await _authService.selectDeviceImei(DEVICE_TOKEN);
|
|
|
|
|
await _authService.selectDeviceImei(localToken);
|
|
|
|
|
if (_authService.hasError) {
|
|
|
|
|
error = _authService.error;
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
@ -378,6 +368,10 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
user =_authService.dashboardItemsList[0];
|
|
|
|
|
sharedPref.setObj(
|
|
|
|
|
LAST_LOGIN_USER, _authService.dashboardItemsList[0]);
|
|
|
|
|
await sharedPref.setString(VIDA_REFRESH_TOKEN_ID,
|
|
|
|
|
user.vidaRefreshTokenID);
|
|
|
|
|
await sharedPref.setString(VIDA_AUTH_TOKEN_ID,
|
|
|
|
|
user.vidaAuthTokenID);
|
|
|
|
|
this.unverified = true;
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
@ -390,22 +384,22 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
/// determine the status of the app
|
|
|
|
|
APP_STATUS get status {
|
|
|
|
|
if (state == ViewState.Busy) {
|
|
|
|
|
app_status = APP_STATUS.LOADING;
|
|
|
|
|
appStatus = APP_STATUS.LOADING;
|
|
|
|
|
} else {
|
|
|
|
|
if(this.doctorProfile !=null)
|
|
|
|
|
app_status = APP_STATUS.AUTHENTICATED;
|
|
|
|
|
appStatus = APP_STATUS.AUTHENTICATED;
|
|
|
|
|
else if (this.unverified) {
|
|
|
|
|
app_status = APP_STATUS.UNVERIFIED;
|
|
|
|
|
appStatus = APP_STATUS.UNVERIFIED;
|
|
|
|
|
} else if (this.isLogin) {
|
|
|
|
|
app_status = APP_STATUS.AUTHENTICATED;
|
|
|
|
|
appStatus = APP_STATUS.AUTHENTICATED;
|
|
|
|
|
} else {
|
|
|
|
|
app_status = APP_STATUS.UNAUTHENTICATED;
|
|
|
|
|
appStatus = APP_STATUS.UNAUTHENTICATED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return app_status;
|
|
|
|
|
return appStatus;
|
|
|
|
|
}
|
|
|
|
|
setAppStatus(APP_STATUS status){
|
|
|
|
|
this.app_status = status;
|
|
|
|
|
this.appStatus = status;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -419,7 +413,7 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
logout({bool isFromLogin = false}) async {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEVICE_TOKEN = "";
|
|
|
|
|
localToken = "";
|
|
|
|
|
String lang = await sharedPref.getString(APP_Language);
|
|
|
|
|
await Helpers.clearSharedPref();
|
|
|
|
|
doctorProfile = null;
|
|
|
|
|
@ -427,7 +421,7 @@ class AuthenticationViewModel extends BaseViewModel {
|
|
|
|
|
deleteUser();
|
|
|
|
|
await getDeviceInfoFromFirebase();
|
|
|
|
|
this.isFromLogin = isFromLogin;
|
|
|
|
|
app_status = APP_STATUS.UNAUTHENTICATED;
|
|
|
|
|
appStatus = APP_STATUS.UNAUTHENTICATED;
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|