From f05b235cd06a70da4e6b01692fb1f4e388daa1e8 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Thu, 12 Nov 2020 08:14:57 +0300 Subject: [PATCH] login issue --- lib/config/config.dart | 7 +-- lib/core/service/client/base_app_client.dart | 18 ++++--- .../check_activation_code_request.dart | 2 +- .../send_activation_request.dart | 2 +- .../components/DocAvailableAppointments.dart | 2 +- .../Covid-DriveThru/Covid-TimeSlots.dart | 2 +- lib/pages/login/confirm-login.dart | 49 +++++++++++++------ lib/pages/login/register-info.dart | 48 +++++++----------- .../authentication/auth_provider.dart | 7 ++- .../family_files/family_files_provider.dart | 19 ++++--- 10 files changed, 86 insertions(+), 70 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index f37bbaea..c4ac1bdb 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -182,7 +182,8 @@ const CHECK_PAYMENT_STATUS = //URL create advance payment const CREATE_ADVANCE_PAYMENT = "Services/Doctors.svc/REST/CreateAdvancePayment"; -const HIS_CREATE_ADVANCE_PAYMENT = "Services/Patients.svc/REST/HIS_CreateAdvancePayment"; +const HIS_CREATE_ADVANCE_PAYMENT = + "Services/Patients.svc/REST/HIS_CreateAdvancePayment"; const ADD_ADVANCE_NUMBER_REQUEST = 'Services/PayFort_Serv.svc/REST/AddAdvancedNumberRequest'; @@ -242,8 +243,8 @@ const LANGUAGE = 2; const PATIENT_OUT_SA = 0; const SESSION_ID = 'TMRhVmkGhOsvamErw'; const IS_DENTAL_ALLOWED_BACKEND = false; -const PATIENT_TYPE = 1; -const PATIENT_TYPE_ID = 1; +const PATIENT_TYPE = 2; +const PATIENT_TYPE_ID = 2; var DEVICE_TOKEN = ""; var DeviceTypeID = Platform.isIOS ? 1 : 2; const LANGUAGE_ID = 2; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index 17467dfb..0d2dda35 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -19,7 +19,9 @@ AppSharedPreferences sharedPref = new AppSharedPreferences(); /// onFailure: (String error, int statusCode) {}, /// body: Map(); /// -AuthenticatedUserObject authenticatedUserObject = locator(); +AuthenticatedUserObject authenticatedUserObject = + locator(); + class BaseAppClient { post(String endPoint, {Map body, @@ -66,21 +68,24 @@ class BaseAppClient { body['PatientType'] = body.containsKey('PatientType') ? body['PatientType'] != null ? body['PatientType'] - : PATIENT_TYPE + : user['PatientType'] != null + ? user['PatientType'] + : null : PATIENT_TYPE; body['PatientTypeID'] = body.containsKey('PatientTypeID') ? body['PatientTypeID'] != null ? body['PatientTypeID'] - : PATIENT_TYPE_ID + : user['PatientTypeID'] != null + ? user['PatientTypeID'] + : null : PATIENT_TYPE_ID; - if (user != null) { body['TokenID'] = token; body['PatientID'] = body['PatientID'] != null ? body['PatientID'] : user['PatientID']; body['PatientOutSA'] = user['OutSA']; - body['SessionID'] = SESSION_ID;//getSessionId(token); + body['SessionID'] = SESSION_ID; //getSessionId(token); } } @@ -117,12 +122,11 @@ class BaseAppClient { onFailure( parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); - } } else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) { onSuccess(parsed, statusCode); - }else if (!parsed['IsAuthenticated']) { + } else if (!parsed['IsAuthenticated']) { await logout(); //helpers.showErrorToast('Your session expired Please login agian'); diff --git a/lib/models/Authentication/check_activation_code_request.dart b/lib/models/Authentication/check_activation_code_request.dart index a4bf79c3..af139ba5 100644 --- a/lib/models/Authentication/check_activation_code_request.dart +++ b/lib/models/Authentication/check_activation_code_request.dart @@ -2,7 +2,7 @@ class CheckActivationCodeReq { int patientMobileNumber; String mobileNo; String deviceToken; - int projectOutSA; + bool projectOutSA; int loginType; String zipCode; bool isRegister; diff --git a/lib/models/Authentication/send_activation_request.dart b/lib/models/Authentication/send_activation_request.dart index 804f6ef0..b53e19b8 100644 --- a/lib/models/Authentication/send_activation_request.dart +++ b/lib/models/Authentication/send_activation_request.dart @@ -2,7 +2,7 @@ class SendActivationRequest { int patientMobileNumber; String mobileNo; String deviceToken; - int projectOutSA; + bool projectOutSA; int loginType; String zipCode; bool isRegister; diff --git a/lib/pages/BookAppointment/components/DocAvailableAppointments.dart b/lib/pages/BookAppointment/components/DocAvailableAppointments.dart index 8d0cc84d..85569473 100644 --- a/lib/pages/BookAppointment/components/DocAvailableAppointments.dart +++ b/lib/pages/BookAppointment/components/DocAvailableAppointments.dart @@ -235,7 +235,7 @@ class _DocAvailableAppointmentsState extends State return children; }, ), - onDaySelected: (date, events, holidays) { + onDaySelected: (date, events) { _onDaySelected(date, events); _animationController.forward(from: 0.0); }, diff --git a/lib/pages/Covid-DriveThru/Covid-TimeSlots.dart b/lib/pages/Covid-DriveThru/Covid-TimeSlots.dart index 1e1fc444..939198c3 100644 --- a/lib/pages/Covid-DriveThru/Covid-TimeSlots.dart +++ b/lib/pages/Covid-DriveThru/Covid-TimeSlots.dart @@ -348,7 +348,7 @@ class _CovidTimeSlotsState extends State return children; }, ), - onDaySelected: (date, event, holidays) { + onDaySelected: (date, event) { _onDaySelected( date, event, diff --git a/lib/pages/login/confirm-login.dart b/lib/pages/login/confirm-login.dart index 2e1ba46b..b6e4dd22 100644 --- a/lib/pages/login/confirm-login.dart +++ b/lib/pages/login/confirm-login.dart @@ -291,7 +291,9 @@ class _ConfirmLogin extends State { checkUserAuthentication(type) { showLoader(true); - var req = getCommonRequest(); + var req = getCommonRequest(type: type); + req.logInTokenID = ""; + var request = CheckPatientAuthenticationReq.fromJson(req.toJson()); GifLoaderDialogUtils.showMyDialog(context); @@ -317,12 +319,11 @@ class _ConfirmLogin extends State { .catchError((err) { print(err); GifLoaderDialogUtils.hideDialog(context); - }); } sendActivationCode(type) async { - var request = this.getCommonRequest(); + var request = this.getCommonRequest(type: type); GifLoaderDialogUtils.showMyDialog(context); await this.authService.sendActivationCode(request).then((result) { GifLoaderDialogUtils.hideDialog(context); @@ -353,10 +354,16 @@ class _ConfirmLogin extends State { localizedReason: 'Scan your fingerprint to authenticate', useErrorDialogs: true, stickyAuth: true); - print(authenticated); + if (authenticated == true) { - var request = this.getCommonRequest(); + + if(user.logInType==2 || user.logInType ==3){ + this.checkActivationCode(); + }else{ + var request = this.getCommonRequest(type: type); this.getMobileInfo(request); + } + } } } @@ -445,30 +452,40 @@ class _ConfirmLogin extends State { //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN); } - getCommonRequest() { + getCommonRequest({type}) { var request = SendActivationRequest(); request.patientMobileNumber = this.mobileNumber; request.mobileNo = '0' + this.mobileNumber.toString(); request.deviceToken = this.deviceToken; - request.projectOutSA = this.patientOutSA == true ? 1 : 0; + request.projectOutSA = this.patientOutSA == true ? true : false; request.loginType = this.selectedOption; - request.oTPSendType = this.selectedOption == 1 ? 1 : 2; + request.oTPSendType = + type == 1 ? type : 2; //this.selectedOption == 1 ? 1 : 2; request.zipCode = this.zipCode; request.logInTokenID = this.loginTokenID ?? ""; if (this.registerd_data != null) { - request.searchType = this.registerd_data.searchType ?? 1; - request.patientID = this.registerd_data.patientID ?? 0; + request.searchType = this.registerd_data.searchType != null + ? this.registerd_data.searchType + : 1; + request.patientID = this.registerd_data.patientID != null + ? this.registerd_data.patientID + : 0; request.patientIdentificationID = request.nationalID = - this.registerd_data.patientIdentificationID ?? '0'; + this.registerd_data.patientIdentificationID != null + ? this.registerd_data.patientIdentificationID + : '0'; request.isRegister = this.registerd_data.isRegister; } else { - request.searchType = request.searchType ?? 2; - request.patientID = this.user.patientID ?? 0; - request.nationalID = request.nationalID ?? '0'; - request.patientIdentificationID = request.patientIdentificationID ?? '0'; + request.searchType = request.searchType != null ? request.searchType : 2; + request.patientID = this.user.patientID != null ? this.user.patientID : 0; + request.nationalID = + request.nationalID != null ? request.nationalID : '0'; + request.patientIdentificationID = request.patientIdentificationID != null + ? request.patientIdentificationID + : '0'; request.isRegister = false; } request.deviceTypeID = request.searchType; @@ -520,7 +537,7 @@ class _ConfirmLogin extends State { checkIfUserAgreedBefore(CheckActivationCode result) { print(result); - if (result.isNeedUserAgreement ==true) { + if (result.isNeedUserAgreement == true) { //move to agreement page. } else { insertIMEI(); diff --git a/lib/pages/login/register-info.dart b/lib/pages/login/register-info.dart index 83e4fc53..e4f69d0d 100644 --- a/lib/pages/login/register-info.dart +++ b/lib/pages/login/register-info.dart @@ -86,7 +86,9 @@ class _RegisterInfo extends State { Container( margin: EdgeInsets.only(bottom: 10), child: TextFields( - hintText: registerInfo.firstNameEn, + hintText: registerInfo.firstNameEn == '-' + ? registerInfo.firstNameAr + : registerInfo.firstNameEn, padding: EdgeInsets.only( top: 20, bottom: 20, left: 10, right: 10), readOnly: true, @@ -95,7 +97,9 @@ class _RegisterInfo extends State { Container( margin: EdgeInsets.only(bottom: 10), child: TextFields( - hintText: registerInfo.secondNameEn, + hintText: registerInfo.secondNameEn == '-' + ? registerInfo.secondNameAr + : registerInfo.secondNameEn, padding: EdgeInsets.only( top: 20, bottom: 20, left: 10, right: 10), readOnly: true, @@ -104,7 +108,9 @@ class _RegisterInfo extends State { Container( margin: EdgeInsets.only(bottom: 10), child: TextFields( - hintText: registerInfo.lastNameEn, + hintText: registerInfo.lastNameEn == '-' + ? registerInfo.lastNameAr + : registerInfo.lastNameEn, padding: EdgeInsets.only( top: 20, bottom: 20, left: 10, right: 10), readOnly: true, @@ -310,9 +316,15 @@ class _RegisterInfo extends State { "PatientIdentificationNo": registerInfo.idNumber, "MobileNumber": registerd_data.patientMobileNumber, "PatientOutSA": registerd_data.zipCode == '966' ? 0 : 1, - "FirstName": registerInfo.firstNameEn, - "MiddleName": registerInfo.secondNameEn, - "LastName": registerInfo.lastNameEn, + "FirstName": registerInfo.firstNameEn == '-' + ? registerInfo.firstNameAr + : registerInfo.firstNameEn, + "MiddleName":registerInfo.secondNameEn == '-' + ? registerInfo.secondNameAr + : registerInfo.secondNameEn, + "LastName": registerInfo.lastNameEn == '-' + ? registerInfo.lastNameAr + : registerInfo.lastNameEn, "StrDateofBirth": registerInfo.dateOfBirth, "DateofBirth": DateUtil.convertISODateToJsonDate( registerInfo.dateOfBirth.replaceAll('/', '-')), @@ -331,30 +343,6 @@ class _RegisterInfo extends State { "PatientIdentificationID": registerInfo.idNumber, "PatientMobileNumber": registerd_data.patientMobileNumber, }; - - // var patientObject ={}; - // var request ={}; - // patientObject['PatientIdentificationType'] = this.identificationType; - // patientObject['PatientIdentificationNo'] = this.id; - // request['PatientIdentificationID'] = this.id; - // request['PatientMobileNumber'] = this.registerInfo.MobileNumber; - // patientObject['MobileNumber'] = this.registerInfo.MobileNumber; - // patientObject['PatientOutSA'] = this.registerInfo.PatientOutSA; - // request['LogInTokenID'] = this.registerInfo.LogInTokenID; - // request['activationCode'] = this.registerInfo.activationCode; - // request['ProjectID'] = this.selectedProjectID; - // patientObject['ProjectID'] = this.selectedProjectID; - // request - // request.setBirthDate(this.dateOfBirth, this.cs.convertISODateToJsonDate(this.dateOfBirth)); - // request.setGender(this.gender); - // request.Patientobject.NationalityID = this.selectedNationalityID; - // request.Patientobject.StrDateofBirth = this.dateOfBirth; - // request.Patientobject.DateofBirthN = this.dateHijri; - // request.Patientobject.EmailAddress = this.eMail; - // request.Patientobject.SourceType = this.iSOCountryID - // request.Patientobject.PreferredLanguage = this.preferredLanguage - // request.Patientobject.Marital = this.maritalStatus; - //return request; } bool isValid() { diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index 8e4191ec..89231d20 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -233,7 +233,7 @@ class AuthProvider with ChangeNotifier { neRequest.languageID = LANGUAGE_ID; neRequest.deviceTypeID = DeviceTypeID; neRequest.patientOutSA = neRequest.zipCode == '966' ? 0 : 1; - neRequest.projectOutSA = neRequest.zipCode == '966' ? 0 : 1; + neRequest.projectOutSA = neRequest.zipCode == '966' ? false : true; neRequest.isDentalAllowedBackend = false; neRequest.forRegisteration = neRequest.isRegister != null ? neRequest.isRegister : false; @@ -345,11 +345,14 @@ class AuthProvider with ChangeNotifier { request.gender = user.gender; request.patientID = user.patientID; request.patientOutSA = user.outSA; - request.loginType = await sharedPref.getInt(LAST_LOGIN) ?? 1; + request.loginType = await sharedPref.getInt(LAST_LOGIN) != null + ? await sharedPref.getInt(LAST_LOGIN) + : 1; request.mACAddress = '00:00:00:00:00:00'; request.latitude = lat; request.longitude = long; request.languageID = int.parse(user.preferredLanguage); + request.patientTypeID = 2; dynamic localRes; try { await new BaseAppClient().post(LOGGED_IN_USER_URL, diff --git a/lib/services/family_files/family_files_provider.dart b/lib/services/family_files/family_files_provider.dart index 4e7c95d0..491d3421 100644 --- a/lib/services/family_files/family_files_provider.dart +++ b/lib/services/family_files/family_files_provider.dart @@ -64,7 +64,8 @@ class FamilyFilesProvider with ChangeNotifier { } } - Future getUserViewRequest(responseID) async { + Future getUserViewRequest( + responseID) async { try { dynamic localRes; Map request = {}; @@ -75,12 +76,13 @@ class FamilyFilesProvider with ChangeNotifier { }, onFailure: (String error, int statusCode) { return Future.error(error); }, body: request); - if(localRes!=null){ - sharedPref.setObject(FAMILY_FILE, localRes); - allSharedRecordsByStatusResponse = GetAllSharedRecordsByStatusResponse.fromJson(localRes); - return Future.value(allSharedRecordsByStatusResponse);} - else - return Future.error("No Data"); + if (localRes != null) { + sharedPref.setObject(FAMILY_FILE, localRes); + allSharedRecordsByStatusResponse = + GetAllSharedRecordsByStatusResponse.fromJson(localRes); + return Future.value(allSharedRecordsByStatusResponse); + } else + return Future.error("No Data"); } catch (error) { print(error); return Future.error(error); @@ -157,7 +159,7 @@ class FamilyFilesProvider with ChangeNotifier { request.zipCode = zipCode; request.patientMobileNumber = int.parse(cellNumber); request.patientIdentificationID = patientIdentificationID; - request.projectOutSA = zipCode == '966' ? 0 : 1; + request.projectOutSA = zipCode == '966' ? false : true; request.loginType = request.searchType = 1; request.oTPSendType = 1; request.isRegister = false; @@ -175,6 +177,7 @@ class FamilyFilesProvider with ChangeNotifier { throw error; } } + //TODO Future checkActivationCode( loginTokenID, activationCode, indentification, mobileNo) async {