Merge branch 'analytics_service' into 'development'

Apply the new authentication logic

See merge request Cloud_Solution/doctor_app_flutter!778
merge-requests/780/merge
Mohammad Aljammal 4 years ago
commit bf8ac21122

@ -64,7 +64,7 @@ class BaseAppClient {
else
body['LanguageID'] = 2;
body['stamp'] = STAMP;
body['stamp'] = DateTime.now().toIso8601String();
// if(!body.containsKey("IPAdress"))
body['IPAdress'] = IP_ADDRESS;
body['VersionID'] = VERSION_ID;

@ -5,8 +5,8 @@ const ONLY_NUMBERS = "[0-9]";
const ONLY_LETTERS = "[a-zA-Z &'\"]";
const ONLY_DATE = "[0-9/]";
const BASE_URL_LIVE_CARE = 'https://livecare.hmg.com/';
const BASE_URL = 'https://hmgwebservices.com/';
// const BASE_URL = 'https://uat.hmgwebservices.com/';
// const BASE_URL = 'https://hmgwebservices.com/';
const BASE_URL = 'https://uat.hmgwebservices.com/';
const PHARMACY_ITEMS_URL = "Services/Lists.svc/REST/GetPharmcyItems_Region_enh";
const PHARMACY_LIST_URL = "Services/Patients.svc/REST/GetPharmcyList";
const PATIENT_PROGRESS_NOTE_URL = "Services/DoctorApplication.svc/REST/GetProgressNoteForInPatient";
@ -279,14 +279,14 @@ var SERVICES_PATIANT_HEADER_AR = [
"المريض الواصل"
];
var DEVICE_TOKEN = "";
const PRIMARY_COLOR = 0xff515B5D;
const TRANSACTION_NO = 0;
const LANGUAGE_ID = 2;
const STAMP = '2020-04-27T12:17:17.721Z';
const IP_ADDRESS = '9.9.9.9';
const VERSION_ID = 6.2;
const VERSION_ID = 6.3;
const CHANNEL = 9;
const SESSION_ID = 'BlUSkYymTt';
const IS_LOGIN_FOR_DOCTOR_APP = true;

@ -12,5 +12,4 @@ final LOGGED_IN_USER = 'loggedUser';
final DASHBOARD_DATA = 'dashboard-data';
final OTP_TYPE = 'otp-type';
final LAST_LOGIN_USER = 'last-login-user';
final PASSWORD = 'password';
final CLINIC_NAME = 'clinic-name';

@ -1,34 +1,26 @@
class ActivationCodeModel {
String mobileNumber;
String zipCode;
int channel;
int languageID;
double versionID;
int memberID;
String password;
int facilityId;
String generalid;
String otpSendType;
ActivationCodeModel(
{this.mobileNumber,
this.zipCode,
this.channel,
{this.channel,
this.languageID,
this.versionID,
this.memberID,
this.password,
this.facilityId,
this.otpSendType,
this.generalid});
ActivationCodeModel.fromJson(Map<String, dynamic> json) {
mobileNumber = json['MobileNumber'];
zipCode = json['ZipCode'];
channel = json['Channel'];
languageID = json['LanguageID'];
versionID = json['VersionID'];
memberID = json['MemberID'];
password = json['Password'];
facilityId = json['facilityId'];
otpSendType = json['OTP_SendType'];
generalid = json['generalid'];
@ -36,13 +28,10 @@ class ActivationCodeModel {
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['MobileNumber'] = this.mobileNumber;
data['ZipCode'] = this.zipCode;
data['Channel'] = this.channel;
data['LanguageID'] = this.languageID;
data['VersionID'] = this.versionID;
data['MemberID'] = this.memberID;
data['Password'] = this.password;
data['facilityId'] = this.facilityId;
data['OTP_SendType'] = otpSendType;
data['generalid'] = this.generalid;

@ -55,8 +55,6 @@ class ActivationCodeForVerificationScreenModel {
data['facilityId'] = this.facilityId;
data['generalid'] = this.generalid;
data['IsMobileFingerPrint'] = this.isMobileFingerPrint;
data['VidaAuthTokenID'] = this.vidaAuthTokenID;
data['VidaRefreshTokenID'] = this.vidaRefreshTokenID;
data['IMEI'] = this.iMEI;
return data;
}

@ -5,11 +5,16 @@ class CheckActivationCodeForDoctorAppResponseModel {
List<ListDoctorsClinic> listDoctorsClinic;
List<DoctorProfileModel> listDoctorProfile;
MemberInformation memberInformation;
String vidaAuthTokenID;
String vidaRefreshTokenID;
CheckActivationCodeForDoctorAppResponseModel(
{this.authenticationTokenID,
this.listDoctorsClinic,
this.memberInformation});
this.memberInformation,
this.listDoctorProfile,
this.vidaAuthTokenID,
this.vidaRefreshTokenID});
CheckActivationCodeForDoctorAppResponseModel.fromJson(
Map<String, dynamic> json) {
@ -27,6 +32,8 @@ class CheckActivationCodeForDoctorAppResponseModel {
listDoctorProfile.add(new DoctorProfileModel.fromJson(v));
});
}
vidaAuthTokenID = json['VidaAuthTokenID'];
vidaRefreshTokenID = json['VidaRefreshTokenID'];
memberInformation = json['memberInformation'] != null
? new MemberInformation.fromJson(json['memberInformation'])
@ -60,12 +67,13 @@ class ListDoctorsClinic {
bool isActive;
String clinicName;
ListDoctorsClinic({this.setupID,
this.projectID,
this.doctorID,
this.clinicID,
this.isActive,
this.clinicName});
ListDoctorsClinic(
{this.setupID,
this.projectID,
this.doctorID,
this.clinicID,
this.isActive,
this.clinicName});
ListDoctorsClinic.fromJson(Map<String, dynamic> json) {
setupID = json['SetupID'];
@ -99,15 +107,16 @@ class MemberInformation {
String preferredLanguage;
List<Roles> roles;
MemberInformation({this.clinics,
this.doctorId,
this.email,
this.employeeId,
this.memberId,
this.memberName,
this.memberNameArabic,
this.preferredLanguage,
this.roles});
MemberInformation(
{this.clinics,
this.doctorId,
this.email,
this.employeeId,
this.memberId,
this.memberName,
this.memberNameArabic,
this.preferredLanguage,
this.roles});
MemberInformation.fromJson(Map<String, dynamic> json) {
if (json['clinics'] != null) {

@ -2,6 +2,9 @@ class CheckActivationCodeRequestModel {
String mobileNumber;
String zipCode;
int doctorID;
int memberID;
String password;
String facilityId;
String iPAdress;
int channel;
int languageID;
@ -12,6 +15,8 @@ class CheckActivationCodeRequestModel {
String activationCode;
String vidaAuthTokenID;
String vidaRefreshTokenID;
String iMEI;
bool isForSilentLogin;
int oTPSendType;
CheckActivationCodeRequestModel(
{this.mobileNumber,
@ -27,7 +32,7 @@ class CheckActivationCodeRequestModel {
this.activationCode,
this.vidaAuthTokenID,
this.vidaRefreshTokenID,
this.oTPSendType});
this.oTPSendType,this.password,this.facilityId,this.memberID,this.isForSilentLogin=false,this.iMEI});
CheckActivationCodeRequestModel.fromJson(Map<String, dynamic> json) {
mobileNumber = json['MobileNumber'];
@ -62,6 +67,11 @@ class CheckActivationCodeRequestModel {
data['VidaAuthTokenID'] = this.vidaAuthTokenID;
data['VidaRefreshTokenID'] = this.vidaRefreshTokenID;
data['OTP_SendType'] = this.oTPSendType;
data['facilityId'] = this.facilityId;
data['MemberID'] = this.memberID;
data['Password'] = this.password;
data['IMEI'] = this.iMEI;
data['IsForSilentLogin'] = this.isForSilentLogin;
return data;
}
}

@ -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);
}

@ -44,8 +44,8 @@ class DashboardViewModel extends BaseViewModel {
_firebaseMessaging.getToken().then((String token) async {
if (token != '') {
DEVICE_TOKEN = token;
authProvider.insertDeviceImei();
// DEVICE_TOKEN = token;
authProvider.insertDeviceImei(token);
}
});
}

@ -432,8 +432,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
Helpers.showErrorToast(authenticationViewModel.error);
GifLoaderDialogUtils.hideDialog(context);
} else {
authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeForDoctorAppRes);
sharedPref.setString(PASSWORD, authenticationViewModel.userInfo.password);
GifLoaderDialogUtils.hideDialog(context);
this.startSMSService(authMethodType);
}
@ -454,13 +453,14 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
GifLoaderDialogUtils.hideDialog(context);
Helpers.showErrorToast(authenticationViewModel.error);
} else {
authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeVerificationScreenRes);
await sharedPref.setString(LOGIN_TOKEN_ID,
authenticationViewModel.activationCodeVerificationScreenRes.logInTokenID);
if (authMethodType == AuthMethodTypes.SMS ||
authMethodType == AuthMethodTypes.WhatsApp) {
GifLoaderDialogUtils.hideDialog(context);
this.startSMSService(authMethodType);
} else {
checkActivationCode();
checkActivationCode(isSilentLogin: true);
}
}
}
@ -541,8 +541,8 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
}
}
checkActivationCode({String value}) async {
await authenticationViewModel.checkActivationCodeForDoctorApp(activationCode: value);
checkActivationCode({String value,bool isSilentLogin = false}) async {
await authenticationViewModel.checkActivationCodeForDoctorApp(activationCode: value,isSilentLogin: isSilentLogin);
if (authenticationViewModel.state == ViewState.ErrorLocal) {
Navigator.pop(context);
Helpers.showErrorToast(authenticationViewModel.error);

@ -657,7 +657,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.4"
version: "1.3.0-nullsafety.3"
mime:
dependency: transitive
description:
@ -949,7 +949,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.2"
version: "1.10.0-nullsafety.1"
sticky_headers:
dependency: "direct main"
description:
@ -1147,5 +1147,5 @@ packages:
source: hosted
version: "2.2.1"
sdks:
dart: ">=2.10.0 <=2.11.0-213.1.beta"
dart: ">=2.10.0 <2.11.0"
flutter: ">=1.22.0 <2.0.0"

Loading…
Cancel
Save