@ -11,22 +11,23 @@ import 'package:doctor_app_flutter/core/model/auth/imei_details.dart';
import ' package:doctor_app_flutter/core/model/auth/insert_imei_model.dart ' ;
import ' package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart ' ;
import ' package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/clinic_model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/doctor_profile_model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/profile_req_Model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/user_model.dart ' ;
import ' package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart ' ;
import ' package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart ' ;
import ' package:doctor_app_flutter/core/service/authentication_service.dart ' ;
import ' package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart ' ;
import ' package:doctor_app_flutter/core/viewModel/base_view_model.dart ' ;
import ' package:doctor_app_flutter/locator.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/clinic_model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/doctor_profile_model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/profile_req_Model.dart ' ;
import ' package:doctor_app_flutter/core/model/doctor/user_model.dart ' ;
import ' package:doctor_app_flutter/utils/dr_app_toast_msg.dart ' ;
import ' package:doctor_app_flutter/utils/utils.dart ' ;
import ' package:doctor_app_flutter/utils/translations_delegate_base_utils.dart ' ;
import ' package:doctor_app_flutter/utils/utils.dart ' ;
import ' package:firebase_messaging/firebase_messaging.dart ' ;
import ' package:flutter/services.dart ' ;
import ' package:local_auth/auth_strings.dart ' ;
/ / import ' package:huawei_hmsavailability/huawei_hmsavailability.dart ' ;
/ / import ' package:local_auth/auth_strings.dart ' ;
import ' package:local_auth/local_auth.dart ' ;
@ -43,20 +44,13 @@ class AuthenticationViewModel extends BaseViewModel {
NewLoginInformationModel get loginInfo = > _authService . loginInfo ;
List < DoctorProfileModel > get doctorProfilesList = >
_authService . doctorProfilesList ;
List < DoctorProfileModel > get doctorProfilesList = > _authService . doctorProfilesList ;
SendActivationCodeForDoctorAppResponseModel
get activationCodeVerificationScreenRes = >
_authService . activationCodeVerificationScreenRes ;
SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes = > _authService . activationCodeVerificationScreenRes ;
SendActivationCodeForDoctorAppResponseModel
get activationCodeForDoctorAppRes = >
_authService . activationCodeForDoctorAppRes ;
SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes = > _authService . activationCodeForDoctorAppRes ;
CheckActivationCodeForDoctorAppResponseModel
get checkActivationCodeForDoctorAppRes = >
_authService . checkActivationCodeForDoctorAppRes ;
CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes = > _authService . checkActivationCodeForDoctorAppRes ;
NewLoginInformationModel loggedUser ;
GetIMEIDetailsModel user ;
@ -91,32 +85,20 @@ class AuthenticationViewModel extends BaseViewModel {
profileInfo [ ' IMEI ' ] = token ;
profileInfo [ ' LogInTypeID ' ] = await sharedPref . getInt ( OTP_TYPE ) ;
profileInfo [ ' BioMetricEnabled ' ] = true ;
profileInfo [ ' MobileNo ' ] =
loggedIn ! = null ? loggedIn [ ' MobileNumber ' ] : user . mobile ;
InsertIMEIDetailsModel insertIMEIDetailsModel =
InsertIMEIDetailsModel . fromJson ( profileInfo ) ;
insertIMEIDetailsModel . genderDescription =
profileInfo [ ' Gender_Description ' ] ;
insertIMEIDetailsModel . genderDescriptionN =
profileInfo [ ' Gender_DescriptionN ' ] ;
insertIMEIDetailsModel . genderDescriptionN =
profileInfo [ ' Gender_DescriptionN ' ] ;
profileInfo [ ' MobileNo ' ] = loggedIn ! = null ? loggedIn [ ' MobileNumber ' ] : user . mobile ;
InsertIMEIDetailsModel insertIMEIDetailsModel = InsertIMEIDetailsModel . fromJson ( profileInfo ) ;
insertIMEIDetailsModel . genderDescription = profileInfo [ ' Gender_Description ' ] ;
insertIMEIDetailsModel . genderDescriptionN = profileInfo [ ' Gender_DescriptionN ' ] ;
insertIMEIDetailsModel . genderDescriptionN = profileInfo [ ' Gender_DescriptionN ' ] ;
insertIMEIDetailsModel . titleDescription = profileInfo [ ' Title_Description ' ] ;
insertIMEIDetailsModel . titleDescriptionN =
profileInfo [ ' Title_DescriptionN ' ] ;
insertIMEIDetailsModel . titleDescriptionN = profileInfo [ ' Title_DescriptionN ' ] ;
insertIMEIDetailsModel . projectID = await sharedPref . getInt ( PROJECT_ID ) ;
insertIMEIDetailsModel . doctorID = loggedIn ! = null
? loggedIn [ ' List_MemberInformation ' ] [ 0 ] [ ' MemberID ' ]
: 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 . doctorID = loggedIn ! = null ? loggedIn [ ' List_MemberInformation ' ] [ 0 ] [ ' MemberID ' ] : 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 = userInfo . password ;
insertIMEIDetailsModel . loginDoctorID = loggedUser ! = null ? loggedUser . listMemberInformation [ 0 ] . employeeID
: int . parse ( user . editedBy . toString ( ) ) ;
insertIMEIDetailsModel . loginDoctorID = loggedUser ! = null ? loggedUser . listMemberInformation [ 0 ] . employeeID : int . parse ( user . editedBy . toString ( ) ) ;
await _authService . insertDeviceImei ( insertIMEIDetailsModel ) ;
if ( _authService . hasError ) {
@ -144,25 +126,22 @@ class AuthenticationViewModel extends BaseViewModel {
}
/ / / send activation code for for msg methods
Future sendActivationCodeVerificationScreen (
AuthMethodTypes authMethodType ) async {
Future sendActivationCodeVerificationScreen ( AuthMethodTypes authMethodType ) async {
setState ( ViewState . BusyLocal ) ;
ActivationCodeForVerificationScreenModel activationCodeModel =
ActivationCodeForVerificationScreenModel (
iMEI: user . iMEI ,
facilityId: user . projectID ,
memberID: user . doctorID ,
loginDoctorID: int . parse ( user . editedBy . toString ( ) ) ,
zipCode: user . outSA = = true ? ' 971 ' : ' 966 ' ,
mobileNumber: user . mobile ,
oTPSendType: authMethodType . getTypeIdService ( ) ,
isMobileFingerPrint: 1 ,
vidaAuthTokenID: user . vidaAuthTokenID ,
vidaRefreshTokenID: user . vidaRefreshTokenID ) ;
ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel (
iMEI: user . iMEI ,
facilityId: user . projectID ,
memberID: user . doctorID ,
loginDoctorID: int . parse ( user . editedBy . toString ( ) ) ,
zipCode: user . outSA = = true ? ' 971 ' : ' 966 ' ,
mobileNumber: user . mobile ,
oTPSendType: authMethodType . getTypeIdService ( ) ,
isMobileFingerPrint: 1 ,
vidaAuthTokenID: user . vidaAuthTokenID ,
vidaRefreshTokenID: user . vidaRefreshTokenID ) ;
await sharedPref . setString ( DOCTOR_ID , user . editedBy . toString ( ) ) ;
await _authService
. sendActivationCodeVerificationScreen ( activationCodeModel ) ;
await _authService . sendActivationCodeVerificationScreen ( activationCodeModel ) ;
if ( _authService . hasError ) {
error = _authService . error ;
setState ( ViewState . ErrorLocal ) ;
@ -171,8 +150,7 @@ class AuthenticationViewModel extends BaseViewModel {
}
/ / / send activation code for silent login
Future sendActivationCodeForDoctorApp (
{ AuthMethodTypes authMethodType , String password } ) async {
Future sendActivationCodeForDoctorApp ( { AuthMethodTypes authMethodType , String password } ) async {
setState ( ViewState . BusyLocal ) ;
int projectID = await sharedPref . getInt ( PROJECT_ID ) ;
ActivationCodeModel activationCodeModel = ActivationCodeModel (
@ -187,57 +165,45 @@ class AuthenticationViewModel extends BaseViewModel {
error = _authService . error ;
setState ( ViewState . ErrorLocal ) ;
} else {
await sharedPref . setString (
TOKEN , _authService . activationCodeForDoctorAppRes . logInTokenID ) ;
await sharedPref . setString ( TOKEN , _authService . activationCodeForDoctorAppRes . logInTokenID ) ;
setState ( ViewState . Idle ) ;
}
}
/ / / check activation code for sms and whats app
Future checkActivationCodeForDoctorApp (
{ String activationCode , bool isSilentLogin = false } ) async {
Future checkActivationCodeForDoctorApp ( { String activationCode , bool isSilentLogin = false } ) async {
setState ( ViewState . BusyLocal ) ;
CheckActivationCodeRequestModel checkActivationCodeForDoctorApp =
new CheckActivationCodeRequestModel (
zipCode: loggedUser ! = null ? loggedUser . zipCode : user . zipCode ,
mobileNumber:
loggedUser ! = null ? loggedUser . mobileNumber : user . mobile ,
projectID: await sharedPref . getInt ( PROJECT_ID ) ! = null
? await sharedPref . getInt ( PROJECT_ID )
: user . projectID ,
logInTokenID: await sharedPref . getString ( TOKEN ) ,
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 ,
loginDoctorID: loggedUser ! = null ? loggedUser . listMemberInformation [ 0 ] . employeeID
: int . parse ( user . editedBy . toString ( ) ) , / / / loggedUser . listMemberInformation [ 0 ] . employeeID ,
/ / loggedUser . listMemberInformation [ 0 ] . employeeID ,
isForSilentLogin: isSilentLogin ,
generalid: " Cs2020@2016 \$ 2958 " ) ;
await _authService
. checkActivationCodeForDoctorApp ( checkActivationCodeForDoctorApp ) ;
CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = new CheckActivationCodeRequestModel (
zipCode: loggedUser ! = null ? loggedUser . zipCode : user . zipCode ,
mobileNumber: loggedUser ! = null ? loggedUser . mobileNumber : user . mobile ,
projectID: await sharedPref . getInt ( PROJECT_ID ) ! = null ? await sharedPref . getInt ( PROJECT_ID ) : user . projectID ,
logInTokenID: await sharedPref . getString ( TOKEN ) ,
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 ,
loginDoctorID: loggedUser ! = null ? loggedUser . listMemberInformation [ 0 ] . employeeID : int . parse ( user . editedBy . toString ( ) ) ,
/ / / loggedUser . listMemberInformation [ 0 ] . employeeID ,
/ / loggedUser . listMemberInformation [ 0 ] . employeeID ,
isForSilentLogin: isSilentLogin ,
generalid: " Cs2020@2016 \$ 2958 " ) ;
await _authService . checkActivationCodeForDoctorApp ( checkActivationCodeForDoctorApp ) ;
if ( _authService . hasError ) {
error = _authService . error ;
setState ( ViewState . ErrorLocal ) ;
} else {
await setDataAfterSendActivationSuccess (
checkActivationCodeForDoctorAppRes ) ;
await setDataAfterSendActivationSuccess ( checkActivationCodeForDoctorAppRes ) ;
setState ( ViewState . Idle ) ;
}
}
/ / / get list of Hospitals
Future getHospitalsList ( memberID ) async {
GetHospitalsRequestModel getHospitalsRequestModel =
GetHospitalsRequestModel ( ) ;
GetHospitalsRequestModel getHospitalsRequestModel = GetHospitalsRequestModel ( ) ;
getHospitalsRequestModel . memberID = memberID ;
getHospitalsRequestModel . doctorID = memberID ;
await _hospitalsService . getHospitals ( getHospitalsRequestModel ) ;
@ -269,17 +235,13 @@ class AuthenticationViewModel extends BaseViewModel {
}
}
/ / / add token to shared preferences in case of send activation code is success
setDataAfterSendActivationSuccess (
CheckActivationCodeForDoctorAppResponseModel
sendActivationCodeForDoctorAppResponseModel ) async {
/ / / add token to shared preferences in case of send activation code is success
setDataAfterSendActivationSuccess ( CheckActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel ) async {
/ / print ( " VerificationCode : " + sendActivationCodeForDoctorAppResponseModel . verificationCode ) ;
await sharedPref . setString ( VIDA_AUTH_TOKEN_ID ,
sendActivationCodeForDoctorAppResponseModel . vidaAuthTokenID ) ;
await sharedPref . setString ( VIDA_REFRESH_TOKEN_ID ,
sendActivationCodeForDoctorAppResponseModel . vidaRefreshTokenID ) ;
await sharedPref . setString ( TOKEN ,
sendActivationCodeForDoctorAppResponseModel . authenticationTokenID ) ;
await sharedPref . setString ( DOCTOR_SETUP_ID , sendActivationCodeForDoctorAppResponseModel . listDoctorsClinic [ 0 ] . setupID ) ;
await sharedPref . setString ( VIDA_AUTH_TOKEN_ID , sendActivationCodeForDoctorAppResponseModel . vidaAuthTokenID ) ;
await sharedPref . setString ( VIDA_REFRESH_TOKEN_ID , sendActivationCodeForDoctorAppResponseModel . vidaRefreshTokenID ) ;
await sharedPref . setString ( TOKEN , sendActivationCodeForDoctorAppResponseModel . authenticationTokenID ) ;
}
saveObjToString ( String key , value ) async {
@ -288,18 +250,10 @@ class AuthenticationViewModel extends BaseViewModel {
/ / / ask user to add his biometric
showIOSAuthMessages ( ) async {
const iosStrings = const IOSAuthMessages (
cancelButton: ' cancel ' ,
goToSettingsButton: ' settings ' ,
goToSettingsDescription: ' Please set up your Touch ID. ' ,
lockOut: ' Please Enable Your Touch ID ' ) ;
const iosStrings = const IOSAuthMessages ( cancelButton: ' cancel ' , goToSettingsButton: ' settings ' , goToSettingsDescription: ' Please set up your Touch ID. ' , lockOut: ' Please Enable Your Touch ID ' ) ;
try {
await auth . authenticateWithBiometrics (
localizedReason: ' Scan your fingerprint to authenticate ' ,
useErrorDialogs: true ,
stickyAuth: true ,
iOSAuthStrings: iosStrings ) ;
await auth . authenticateWithBiometrics ( localizedReason: ' Scan your fingerprint to authenticate ' , useErrorDialogs: true , stickyAuth: true , iOSAuthStrings: iosStrings ) ;
} on PlatformException catch ( e ) {
DrAppToastMsg . showErrorToast ( e . toString ( ) ) ;
}
@ -312,12 +266,7 @@ class AuthenticationViewModel extends BaseViewModel {
/ / / get doctor profile based on clinic model
Future getDoctorProfileBasedOnClinic ( ClinicModel clinicInfo ) async {
ProfileReqModel docInfo = new ProfileReqModel (
doctorID: clinicInfo . doctorID ,
clinicID: clinicInfo . clinicID ,
license: true ,
projectID: clinicInfo . projectID ,
languageID: 2 ) ;
ProfileReqModel docInfo = new ProfileReqModel ( doctorID: clinicInfo . doctorID , clinicID: clinicInfo . clinicID , license: true , projectID: clinicInfo . projectID , languageID: 2 ) ;
/ / / TODO change the lan
await _authService . getDoctorProfileBasedOnClinic ( docInfo ) ;
@ -332,17 +281,12 @@ class AuthenticationViewModel extends BaseViewModel {
/ / / add some logic in case of check activation code is success
onCheckActivationCodeSuccess ( { bool isSilentLogin = false } ) async {
sharedPref . setString (
TOKEN , checkActivationCodeForDoctorAppRes . authenticationTokenID ) ;
if ( checkActivationCodeForDoctorAppRes . listDoctorProfile ! = null & &
checkActivationCodeForDoctorAppRes . listDoctorProfile . isNotEmpty ) {
localSetDoctorProfile (
checkActivationCodeForDoctorAppRes . listDoctorProfile [ 0 ] ) ;
sharedPref . setString ( TOKEN , checkActivationCodeForDoctorAppRes . authenticationTokenID ) ;
if ( checkActivationCodeForDoctorAppRes . listDoctorProfile ! = null & & checkActivationCodeForDoctorAppRes . listDoctorProfile . isNotEmpty ) {
localSetDoctorProfile ( checkActivationCodeForDoctorAppRes . listDoctorProfile [ 0 ] ) ;
} else {
sharedPref . setObj (
CLINIC_NAME , checkActivationCodeForDoctorAppRes . listDoctorsClinic ) ;
ClinicModel clinic = ClinicModel . fromJson (
checkActivationCodeForDoctorAppRes . listDoctorsClinic [ 0 ] . toJson ( ) ) ;
sharedPref . setObj ( CLINIC_NAME , checkActivationCodeForDoctorAppRes . listDoctorsClinic ) ;
ClinicModel clinic = ClinicModel . fromJson ( checkActivationCodeForDoctorAppRes . listDoctorsClinic [ 0 ] . toJson ( ) ) ;
await getDoctorProfileBasedOnClinic ( clinic ) ;
}
}
@ -387,7 +331,7 @@ class AuthenticationViewModel extends BaseViewModel {
setState ( ViewState . Busy ) ;
try {
token = await _firebaseMessaging . getToken ( ) ;
} catch ( ex ) {
} catch ( ex ) {
print ( ex ) ;
}
@ -401,10 +345,8 @@ class AuthenticationViewModel extends BaseViewModel {
} else {
if ( _authService . dashboardItemsList . length > 0 ) {
user = _authService . dashboardItemsList [ 0 ] ;
sharedPref . setObj (
LAST_LOGIN_USER , _authService . dashboardItemsList [ 0 ] ) ;
await sharedPref . setString (
VIDA_REFRESH_TOKEN_ID , user . vidaRefreshTokenID ) ;
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 ;
}