From 41b438fd747705973a847fd3f729b473a16e3e35 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Tue, 4 Aug 2020 18:23:16 +0300 Subject: [PATCH 1/4] login page changes --- lib/config/shared_pref_kay.dart | 1 + .../insert_device_imei_request.dart | 251 ------------------ lib/pages/landing/landing_page.dart | 3 +- lib/pages/login/confirm-login.dart | 18 +- .../authentication/auth_provider.dart | 15 +- lib/widgets/otp/sms-popup.dart | 29 ++ 6 files changed, 58 insertions(+), 259 deletions(-) diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart index a4f11077..cbf523bd 100644 --- a/lib/config/shared_pref_kay.dart +++ b/lib/config/shared_pref_kay.dart @@ -8,3 +8,4 @@ const REGISTER_DATA_FOR_LOGIIN = 'register-data-for-login'; const LAST_LOGIN = 'last-login'; const ONLY_SMS = 'only-sms'; const AUTH_DATA = 'auth-data'; +const IMEI_USER_DATA = 'imei-user-data'; diff --git a/lib/models/Authentication/insert_device_imei_request.dart b/lib/models/Authentication/insert_device_imei_request.dart index 474e6194..02e3b278 100644 --- a/lib/models/Authentication/insert_device_imei_request.dart +++ b/lib/models/Authentication/insert_device_imei_request.dart @@ -3,69 +3,14 @@ class INSERTDeviceIMEIRequest { int patientType; int patientID; String firstName; - String middleName; - String lastName; String firstNameN; - String middleNameN; String lastNameN; - int relationshipID; - int gender; - String dateofBirth; - Null dateofBirthN; - String nationalityID; - Null phoneResi; - Null phoneOffice; - String mobileNumber; - Null faxNumber; - String emailAddress; - Null bloodGroup; - Null rHFactor; - bool isEmailAlertRequired; - bool isSMSAlertRequired; int preferredLanguage; - bool isPrivilegedMember; - Null memberID; - Null expiryDate; - Null isHmgEmployee; - Null employeeID; - Null emergencyContactName; - Null emergencyContactNo; - int patientPayType; - Null dHCCPatientRefID; - bool isPatientDummy; - int status; - Null isStatusCleared; - int patientIdentificationType; String patientIdentificationNo; - int projectID; - int infoSourceID; - Null address; - int age; - String ageDesc; - int areaID; - int createdBy; - String genderDescription; - Null iR; - Null iSOCityID; - Null iSOCountryID; - List listPrivilege; - Null marital; bool outSA; - Null pOBox; - bool receiveHealthSummaryReport; - int sourceType; - Null strDateofBirth; - Null tempAddress; - String zipCode; - - String patientName; String identificationNo; - Null email; String mobileNo; - bool patientOutSA; - String tokenID; - Null patientBloodType; String iMEI; bool biometricEnabled; int logInTypeID; @@ -75,67 +20,14 @@ class INSERTDeviceIMEIRequest { this.patientType, this.patientID, this.firstName, - this.middleName, - this.lastName, this.firstNameN, - this.middleNameN, this.lastNameN, - this.relationshipID, - this.gender, - this.dateofBirth, - this.dateofBirthN, - this.nationalityID, - this.phoneResi, - this.phoneOffice, - this.mobileNumber, - this.faxNumber, - this.emailAddress, - this.bloodGroup, - this.rHFactor, - this.isEmailAlertRequired, - this.isSMSAlertRequired, this.preferredLanguage, - this.isPrivilegedMember, - this.memberID, - this.expiryDate, - this.isHmgEmployee, - this.employeeID, - this.emergencyContactName, - this.emergencyContactNo, - this.patientPayType, - this.dHCCPatientRefID, - this.isPatientDummy, - this.status, - this.isStatusCleared, - this.patientIdentificationType, this.patientIdentificationNo, - this.projectID, - this.infoSourceID, - this.address, - this.age, - this.ageDesc, - this.areaID, - this.createdBy, - this.genderDescription, - this.iR, - this.iSOCityID, - this.iSOCountryID, - this.listPrivilege, - this.marital, this.outSA, - this.pOBox, - this.receiveHealthSummaryReport, - this.sourceType, - this.strDateofBirth, - this.tempAddress, - this.zipCode, - this.patientName, this.identificationNo, - this.email, this.mobileNo, - this.patientOutSA, this.tokenID, - this.patientBloodType, this.iMEI, this.biometricEnabled, this.logInTypeID}); @@ -145,74 +37,14 @@ class INSERTDeviceIMEIRequest { patientType = json['PatientType']; patientID = json['PatientID']; firstName = json['FirstName']; - middleName = json['MiddleName']; - lastName = json['LastName']; firstNameN = json['FirstNameN']; - middleNameN = json['MiddleNameN']; lastNameN = json['LastNameN']; - relationshipID = json['RelationshipID']; - gender = json['Gender']; - dateofBirth = json['DateofBirth']; - dateofBirthN = json['DateofBirthN']; - nationalityID = json['NationalityID']; - phoneResi = json['PhoneResi']; - phoneOffice = json['PhoneOffice']; - mobileNumber = json['MobileNumber']; - faxNumber = json['FaxNumber']; - emailAddress = json['EmailAddress']; - bloodGroup = json['BloodGroup']; - rHFactor = json['RHFactor']; - isEmailAlertRequired = json['IsEmailAlertRequired']; - isSMSAlertRequired = json['IsSMSAlertRequired']; preferredLanguage = json['PreferredLanguage']; - isPrivilegedMember = json['IsPrivilegedMember']; - memberID = json['MemberID']; - expiryDate = json['ExpiryDate']; - isHmgEmployee = json['IsHmgEmployee']; - employeeID = json['EmployeeID']; - emergencyContactName = json['EmergencyContactName']; - emergencyContactNo = json['EmergencyContactNo']; - patientPayType = json['PatientPayType']; - dHCCPatientRefID = json['DHCCPatientRefID']; - isPatientDummy = json['IsPatientDummy']; - status = json['Status']; - isStatusCleared = json['IsStatusCleared']; - patientIdentificationType = json['PatientIdentificationType']; patientIdentificationNo = json['PatientIdentificationNo']; - projectID = json['ProjectID']; - infoSourceID = json['InfoSourceID']; - address = json['Address']; - age = json['Age']; - ageDesc = json['AgeDesc']; - areaID = json['AreaID']; - createdBy = json['CreatedBy']; - genderDescription = json['GenderDescription']; - iR = json['IR']; - iSOCityID = json['ISOCityID']; - iSOCountryID = json['ISOCountryID']; - if (json['ListPrivilege'] != null) { - listPrivilege = new List(); - json['ListPrivilege'].forEach((v) { - listPrivilege.add(new ListPrivilege.fromJson(v)); - }); - } - marital = json['Marital']; outSA = json['OutSA']; - pOBox = json['POBox']; - receiveHealthSummaryReport = json['ReceiveHealthSummaryReport']; - sourceType = json['SourceType']; - strDateofBirth = json['StrDateofBirth']; - tempAddress = json['TempAddress']; - zipCode = json['ZipCode']; - - patientName = json['PatientName']; identificationNo = json['IdentificationNo']; - email = json['Email']; mobileNo = json['MobileNo']; - patientOutSA = json['PatientOutSA']; - tokenID = json['TokenID']; - patientBloodType = json['PatientBloodType']; iMEI = json['IMEI']; biometricEnabled = json['BiometricEnabled']; logInTypeID = json['LogInTypeID']; @@ -224,100 +56,17 @@ class INSERTDeviceIMEIRequest { data['PatientType'] = this.patientType; data['PatientID'] = this.patientID; data['FirstName'] = this.firstName; - data['MiddleName'] = this.middleName; - data['LastName'] = this.lastName; data['FirstNameN'] = this.firstNameN; - data['MiddleNameN'] = this.middleNameN; data['LastNameN'] = this.lastNameN; - data['RelationshipID'] = this.relationshipID; - data['Gender'] = this.gender; - data['DateofBirth'] = this.dateofBirth; - data['DateofBirthN'] = this.dateofBirthN; - data['NationalityID'] = this.nationalityID; - data['PhoneResi'] = this.phoneResi; - data['PhoneOffice'] = this.phoneOffice; - data['MobileNumber'] = this.mobileNumber; - data['FaxNumber'] = this.faxNumber; - data['EmailAddress'] = this.emailAddress; - data['BloodGroup'] = this.bloodGroup; - data['RHFactor'] = this.rHFactor; - data['IsEmailAlertRequired'] = this.isEmailAlertRequired; - data['IsSMSAlertRequired'] = this.isSMSAlertRequired; data['PreferredLanguage'] = this.preferredLanguage; - data['IsPrivilegedMember'] = this.isPrivilegedMember; - data['MemberID'] = this.memberID; - data['ExpiryDate'] = this.expiryDate; - data['IsHmgEmployee'] = this.isHmgEmployee; - data['EmployeeID'] = this.employeeID; - data['EmergencyContactName'] = this.emergencyContactName; - data['EmergencyContactNo'] = this.emergencyContactNo; - data['PatientPayType'] = this.patientPayType; - data['DHCCPatientRefID'] = this.dHCCPatientRefID; - data['IsPatientDummy'] = this.isPatientDummy; - data['Status'] = this.status; - data['IsStatusCleared'] = this.isStatusCleared; - data['PatientIdentificationType'] = this.patientIdentificationType; data['PatientIdentificationNo'] = this.patientIdentificationNo; - data['ProjectID'] = this.projectID; - data['InfoSourceID'] = this.infoSourceID; - data['Address'] = this.address; - data['Age'] = this.age; - data['AgeDesc'] = this.ageDesc; - data['AreaID'] = this.areaID; - data['CreatedBy'] = this.createdBy; - data['GenderDescription'] = this.genderDescription; - data['IR'] = this.iR; - data['ISOCityID'] = this.iSOCityID; - data['ISOCountryID'] = this.iSOCountryID; - if (this.listPrivilege != null) { - data['ListPrivilege'] = - this.listPrivilege.map((v) => v.toJson()).toList(); - } - data['Marital'] = this.marital; data['OutSA'] = this.outSA; - data['POBox'] = this.pOBox; - data['ReceiveHealthSummaryReport'] = this.receiveHealthSummaryReport; - data['SourceType'] = this.sourceType; - data['StrDateofBirth'] = this.strDateofBirth; - data['TempAddress'] = this.tempAddress; - data['ZipCode'] = this.zipCode; - - data['PatientName'] = this.patientName; data['IdentificationNo'] = this.identificationNo; - data['Email'] = this.email; data['MobileNo'] = this.mobileNo; - data['PatientOutSA'] = this.patientOutSA; - data['TokenID'] = this.tokenID; - data['PatientBloodType'] = this.patientBloodType; data['IMEI'] = this.iMEI; data['BiometricEnabled'] = this.biometricEnabled; data['LogInTypeID'] = this.logInTypeID; return data; } } - -class ListPrivilege { - int iD; - String serviceName; - bool previlege; - Null region; - - ListPrivilege({this.iD, this.serviceName, this.previlege, this.region}); - - ListPrivilege.fromJson(Map json) { - iD = json['ID']; - serviceName = json['ServiceName']; - previlege = json['Previlege']; - region = json['Region']; - } - - Map toJson() { - final Map data = new Map(); - data['ID'] = this.iD; - data['ServiceName'] = this.serviceName; - data['Previlege'] = this.previlege; - data['Region'] = this.region; - return data; - } -} diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index bf1ac847..ef36b0ef 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -97,7 +97,8 @@ class _LandingPageState extends State { .then((SelectDeviceIMEIRES value) => setUserValues(value)); } - void setUserValues(value) { + void setUserValues(value) async { print(value); + sharedPref.setObject(IMEI_USER_DATA, value); } } diff --git a/lib/pages/login/confirm-login.dart b/lib/pages/login/confirm-login.dart index 3d5f181e..7d011fbd 100644 --- a/lib/pages/login/confirm-login.dart +++ b/lib/pages/login/confirm-login.dart @@ -54,6 +54,10 @@ class _ConfirmLogin extends State { bool onlySMSBox = false; var userData; + + static BuildContext _context; + + static bool _loading; @override void initState() { _getAvailableBiometrics(); @@ -509,15 +513,17 @@ class _ConfirmLogin extends State { } checkActivationCode({value}) { - loading(true); + SMSOTP.showLoadingDialog(context, true); var request = this.getCommonRequest().toJson(); this.authService.checkActivationCode(request, value).then((result) => { this.userData = result.list, //AuthenticatedUser.fromJson(result['List'][0]), this.sharedPref.setObject(USER_PROFILE, result.list), this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), + this.sharedPref.setString(TOKEN, result.authenticationTokenID), this.checkIfUserAgreedBefore(result), - loading(false) + Navigator.of(context).pop(), + SMSOTP.showLoadingDialog(context, false), }); } @@ -526,13 +532,17 @@ class _ConfirmLogin extends State { if (result.isNeedUserAgreement) { //move to agreement page. } else { - goToHome(); + insertIMEI(); } } + insertIMEI() { + authService.insertDeviceImei().then((value) => {goToHome()}); + } + goToHome() { authService.insertDeviceImei().then((value) => print(value)); - // Navigator.of(context).pushNamed(HOME); + Navigator.of(context).pushNamed(HOME); // const request = new LoginRequest(); // if (this.loginType === AuthenticationService.IDENTIFCIATION_LOGIN_TYPE) { // request.PatientID = 0; diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index 40e76236..0e35964d 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -33,7 +33,7 @@ const CHECK_ACTIVATION_CODE = '/Authentication.svc/REST/CheckActivationCode'; class AuthProvider with ChangeNotifier { bool isLogin = false; bool isLoading = true; - var authenticatedUser; + dynamic authenticatedUser; AuthProvider() { getUserAuthentication(); } @@ -89,6 +89,7 @@ class AuthProvider with ChangeNotifier { var request = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); var newRequest = INSERTDeviceIMEIRequest(); + var imei = await sharedPref.getString(PUSH_TOKEN); // if (!request.) { newRequest.iMEI = imei; @@ -99,6 +100,13 @@ class AuthProvider with ChangeNotifier { newRequest.biometricEnabled = false; newRequest.preferredLanguage = int.parse(request.preferredLanguage) ?? 1; newRequest.logInTypeID = lastLogin ?? 1; + newRequest.patientID = request.patientID; + newRequest.mobileNo = request.mobileNumber; + newRequest.identificationNo = request.patientIdentificationNo; + newRequest.patientIdentificationNo = request.patientIdentificationNo; + newRequest.patientType = request.patientType; + newRequest.setupID = request.setupID; + newRequest.tokenID = await sharedPref.getString(TOKEN); // } await new BaseAppClient().post(INSERT_DEVICE_IMEI, @@ -121,7 +129,8 @@ class AuthProvider with ChangeNotifier { request['IMEI'] = imei; await new BaseAppClient().post(SELECT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) { - localRes = response; + localRes = SelectDeviceIMEIRES.fromJson( + response['Patient_SELECTDeviceIMEIbyIMEIList'][0]); }, onFailure: (String error, int statusCode) { throw error; }, body: request); @@ -189,7 +198,7 @@ class AuthProvider with ChangeNotifier { request.patientOutSA = request.zipCode == '966' ? 0 : 1; request.isDentalAllowedBackend = false; try { - var localRes; + dynamic localRes; await new BaseAppClient().post(SEND_ACTIVATION_CODE, onSuccess: (dynamic response, int statusCode) { localRes = response; diff --git a/lib/widgets/otp/sms-popup.dart b/lib/widgets/otp/sms-popup.dart index 6d93552b..75a2eda7 100644 --- a/lib/widgets/otp/sms-popup.dart +++ b/lib/widgets/otp/sms-popup.dart @@ -17,6 +17,10 @@ class SMSOTP { Future timer; + static BuildContext _context; + + static bool _loading; + SMSOTP( this.context, this.type, @@ -277,4 +281,29 @@ class SMSOTP { } }); } + + static void showLoadingDialog(BuildContext context, bool _loading) async { + _context = context; + _loading = true; + if (_loading == false) { + Navigator.of(context).pop(); + return; + } + await showDialog( + context: _context, + barrierDismissible: false, + builder: (BuildContext context) { + return SimpleDialog( + elevation: 0.0, + backgroundColor: Colors.transparent, + children: [ + Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Colors.black), + ), + ) + ], + ); + }); + } } From 8d0834ff3e853a48c0be58f52e48630cdab6a8b4 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Thu, 6 Aug 2020 09:15:48 +0300 Subject: [PATCH 2/4] login inprogress --- assets/images/login/more_icon.png | Bin 0 -> 488 bytes lib/config/localized_values.dart | 11 +- lib/core/service/client/base_app_client.dart | 9 + lib/locator.dart | 1 + .../Authentication/authenticated_user.dart | 54 +- .../check_activation_code_response.dart | 114 +-- lib/pages/login/confirm-login.dart | 662 +++++++++++------- lib/pages/login/login.dart | 46 +- lib/pages/login/welcome.dart | 18 +- lib/routes.dart | 1 + .../authentication/auth_provider.dart | 8 +- lib/uitl/translations_delegate_base.dart | 6 + lib/widgets/drawer/app_drawer_widget.dart | 38 +- lib/widgets/others/app_scaffold_widget.dart | 4 + lib/widgets/otp/sms-popup.dart | 2 +- 15 files changed, 614 insertions(+), 360 deletions(-) create mode 100644 assets/images/login/more_icon.png diff --git a/assets/images/login/more_icon.png b/assets/images/login/more_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b696d345a329b1fc4d647bf3802be648ecea8b66 GIT binary patch literal 488 zcmVP)XtjE*#J+IBZn#6oSKE^a6??=qm0McP_G#2%;2L zYonbQQ-x{Y4}s8~`ulr-!b?|mQ$F8CidujveT@UXz%y_MTmpx{u^#)TQt2`6aH=X? zKi0qJNDFux*aU`tU@8J@z`@rOP74cyqdAvr`*;tm1G_-guTv$TnFHE^GvGBoQ7%8# zQ2wsO^@HR{1}tW)H4}Ym5@-cZ;v>d|ZDfSQC674Z8DOUlv!v-YaD#1O1z959WCh7xb4fR2CM0)GtC5u;(91`%Tqv435Hb@Q$ zxZBaN$50z2M^vdBYk-2}kboZ?{VZNVa!9~ej)v!k+8{Y3;3G#vi&u~w-i^kfG*B71 z!Osjw{3o|$G!re#q73!Iv78YOw>;umg!Jwm+C$f)tz_?Rm;p%t-U&=Jn8PiP> localizedValues = { "arabic-change": {"en": "عربي", "ar": "English"}, "notification": {"en": "Notifications", "ar": "إشعارات"}, "app-settings": {"en": "App Settings", "ar": "إعدادات التطبيق"}, - "rate-app": {"en": "Rate Our App", "ar": "قيم التطبيق"} + "rate-app": {"en": "Rate Our App", "ar": "قيم التطبيق"}, + "more-verify": { + "en": "More Verification Options", + "ar": "المزيد من خيارات التحقق" + }, + "welcome-back": {"en": "Welcome back!", "ar": "مرحبا بعودتك!"}, + "account-info": { + "en": "Would you like to login with current username?", + "ar": "هل ترغب في تسجيل الدخول باسم المستخدم الحالي؟" + }, }; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index 026ef6c6..d4e3d8be 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -1,8 +1,11 @@ import 'dart:convert'; import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; AppSharedPreferences sharedPref = new AppSharedPreferences(); @@ -43,6 +46,8 @@ class BaseAppClient { if (!parsed['IsAuthenticated']) { if (parsed['isSMSSent'] == true) { onSuccess(parsed, statusCode); + } else { + logout(); } // await helpers.logout(); //helpers.showErrorToast('Your session expired Please login agian'); @@ -63,4 +68,8 @@ class BaseAppClient { onFailure(e.toString(), -1); } } + + logout() async { + await sharedPref.remove(LOGIN_TOKEN_ID); + } } diff --git a/lib/locator.dart b/lib/locator.dart index f6a76c1c..4a996519 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/routes.dart'; import 'package:get_it/get_it.dart'; import 'core/service/hospital_service.dart'; diff --git a/lib/models/Authentication/authenticated_user.dart b/lib/models/Authentication/authenticated_user.dart index 40145b87..7ca3a3e2 100644 --- a/lib/models/Authentication/authenticated_user.dart +++ b/lib/models/Authentication/authenticated_user.dart @@ -11,55 +11,55 @@ class AuthenticatedUser { int relationshipID; int gender; String dateofBirth; - Null dateofBirthN; + dynamic dateofBirthN; String nationalityID; - Null phoneResi; - Null phoneOffice; + dynamic phoneResi; + dynamic phoneOffice; String mobileNumber; - Null faxNumber; + dynamic faxNumber; String emailAddress; - Null bloodGroup; - Null rHFactor; + dynamic bloodGroup; + dynamic rHFactor; bool isEmailAlertRequired; bool isSMSAlertRequired; String preferredLanguage; bool isPrivilegedMember; - Null memberID; - Null expiryDate; - Null isHmgEmployee; - Null employeeID; - Null emergencyContactName; - Null emergencyContactNo; + dynamic memberID; + dynamic expiryDate; + dynamic isHmgEmployee; + dynamic employeeID; + dynamic emergencyContactName; + dynamic emergencyContactNo; int patientPayType; - Null dHCCPatientRefID; + dynamic dHCCPatientRefID; bool isPatientDummy; int status; - Null isStatusCleared; + dynamic isStatusCleared; int patientIdentificationType; String patientIdentificationNo; int projectID; int infoSourceID; - Null address; + dynamic address; int age; String ageDesc; int areaID; int createdBy; String genderDescription; - Null iR; - Null iSOCityID; - Null iSOCountryID; + dynamic iR; + dynamic iSOCityID; + dynamic iSOCountryID; List listPrivilege; - Null marital; + dynamic marital; int outSA; - Null pOBox; + dynamic pOBox; bool receiveHealthSummaryReport; int sourceType; - Null strDateofBirth; - Null tempAddress; - Null zipCode; - // Null patientPayType; - // Null patientType; - // Null status; + dynamic strDateofBirth; + dynamic tempAddress; + dynamic zipCode; + // dynamic patientPayType; + // dynamic patientType; + // dynamic status; AuthenticatedUser({ this.setupID, @@ -260,7 +260,7 @@ class ListPrivilege { int iD; String serviceName; bool previlege; - Null region; + dynamic region; ListPrivilege({this.iD, this.serviceName, this.previlege, this.region}); diff --git a/lib/models/Authentication/check_activation_code_response.dart b/lib/models/Authentication/check_activation_code_response.dart index afa0057a..3a0aed65 100644 --- a/lib/models/Authentication/check_activation_code_response.dart +++ b/lib/models/Authentication/check_activation_code_response.dart @@ -1,68 +1,68 @@ import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; class CheckActivationCode { - Null date; + dynamic date; int languageID; int serviceName; - Null time; - Null androidLink; + dynamic time; + dynamic androidLink; String authenticationTokenID; - Null data; + dynamic data; bool dataw; int dietType; - Null errorCode; - Null errorEndUserMessage; - Null errorEndUserMessageN; - Null errorMessage; + dynamic errorCode; + dynamic errorEndUserMessage; + dynamic errorEndUserMessageN; + dynamic errorMessage; int errorType; int foodCategory; - Null iOSLink; + dynamic iOSLink; bool isAuthenticated; int mealOrderStatus; int mealType; int messageStatus; int numberOfResultRecords; - Null patientBlodType; - Null successMsg; - Null successMsgN; - Null doctorInformationList; - Null getAllPendingRecordsList; - Null getAllSharedRecordsByStatusList; - Null getResponseFileList; + dynamic patientBlodType; + dynamic successMsg; + dynamic successMsgN; + dynamic doctorInformationList; + dynamic getAllPendingRecordsList; + dynamic getAllSharedRecordsByStatusList; + dynamic getResponseFileList; bool isHMGPatient; bool isLoginSuccessfully; bool isNeedUpdateIdintificationNo; bool kioskSendSMS; AuthenticatedUser list; - Null listAskHabibMobileLoginInfo; - Null listAskHabibPatientFile; - Null listMergeFiles; - Null listMobileLoginInfo; - Null listPatientCount; - Null logInTokenID; - Null mohemmPrivilegeList; + dynamic listAskHabibMobileLoginInfo; + dynamic listAskHabibPatientFile; + dynamic listMergeFiles; + dynamic listMobileLoginInfo; + dynamic listPatientCount; + dynamic logInTokenID; + dynamic mohemmPrivilegeList; int pateintID; - Null patientBloodType; + String patientBloodType; bool patientHasFile; - Null patientMergedIDs; + dynamic patientMergedIDs; bool patientOutSA; int patientShareRequestID; int patientType; int projectIDOut; - Null returnMessage; + dynamic returnMessage; bool sMSLoginRequired; - Null servicePrivilegeList; - Null sharePatientName; - Null verificationCode; - Null email; - Null errorList; + dynamic servicePrivilegeList; + dynamic sharePatientName; + dynamic verificationCode; + dynamic email; + dynamic errorList; bool hasFile; bool isActiveCode; bool isMerged; bool isNeedUserAgreement; bool isSMSSent; - Null memberList; - Null message; + dynamic memberList; + dynamic message; int statusCode; CheckActivationCode( @@ -283,52 +283,52 @@ class List { int relationshipID; int gender; String dateofBirth; - Null dateofBirthN; + dynamic dateofBirthN; String nationalityID; - Null phoneResi; - Null phoneOffice; + dynamic phoneResi; + dynamic phoneOffice; String mobileNumber; - Null faxNumber; + dynamic faxNumber; String emailAddress; - Null bloodGroup; - Null rHFactor; + dynamic bloodGroup; + dynamic rHFactor; bool isEmailAlertRequired; bool isSMSAlertRequired; String preferredLanguage; bool isPrivilegedMember; - Null memberID; - Null expiryDate; - Null isHmgEmployee; - Null employeeID; - Null emergencyContactName; - Null emergencyContactNo; + dynamic memberID; + dynamic expiryDate; + dynamic isHmgEmployee; + dynamic employeeID; + dynamic emergencyContactName; + dynamic emergencyContactNo; int patientPayType; - Null dHCCPatientRefID; + dynamic dHCCPatientRefID; bool isPatientDummy; int status; - Null isStatusCleared; + dynamic isStatusCleared; int patientIdentificationType; String patientIdentificationNo; int projectID; int infoSourceID; - Null address; + dynamic address; int age; String ageDesc; int areaID; int createdBy; String genderDescription; - Null iR; - Null iSOCityID; - Null iSOCountryID; + dynamic iR; + dynamic iSOCityID; + dynamic iSOCountryID; ListPrivilege listPrivilege; - Null marital; + dynamic marital; int outSA; - Null pOBox; + dynamic pOBox; bool receiveHealthSummaryReport; int sourceType; - Null strDateofBirth; - Null tempAddress; - Null zipCode; + dynamic strDateofBirth; + dynamic tempAddress; + dynamic zipCode; List({ this.setupID, @@ -525,7 +525,7 @@ class ListPrivilege { int iD; String serviceName; bool previlege; - Null region; + dynamic region; ListPrivilege({this.iD, this.serviceName, this.previlege, this.region}); diff --git a/lib/pages/login/confirm-login.dart b/lib/pages/login/confirm-login.dart index 7d011fbd..c53291f8 100644 --- a/lib/pages/login/confirm-login.dart +++ b/lib/pages/login/confirm-login.dart @@ -1,13 +1,13 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; -import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart'; - +import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart'; import 'package:diplomaticquarterapp/models/Authentication/send_activation_request.dart'; -import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_request.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/card/rounded_container.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; @@ -18,7 +18,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_flexible_toast/flutter_flexible_toast.dart'; +import 'package:intl/intl.dart'; import 'package:local_auth/local_auth.dart'; class ConfirmLogin extends StatefulWidget { @@ -28,16 +28,16 @@ class ConfirmLogin extends StatefulWidget { class _ConfirmLogin extends State { final LocalAuthentication auth = LocalAuthentication(); - List _availableBiometrics; + dynamic _availableBiometrics; var sharedPref = new AppSharedPreferences(); bool authenticated; final authService = new AuthProvider(); int mobileNumber; String errorMsg = ''; - var user; + SelectDeviceIMEIRES user; bool isLoading = false; CheckPatientAuthenticationReq registerd_data; - + bool isMoreOption = false; var zipCode; var patientOutSA; @@ -58,6 +58,7 @@ class _ConfirmLogin extends State { static BuildContext _context; static bool _loading; + @override void initState() { _getAvailableBiometrics(); @@ -80,227 +81,145 @@ class _ConfirmLogin extends State { children: [ Expanded( flex: 3, - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/habib-logo.png', - height: 80, - width: 80, - ), - this.onlySMSBox == false - ? AppText( - TranslationBase.of(context) - .verifyLoginWith, - fontSize: - SizeConfig.textMultiplier * 3.5, - textAlign: TextAlign.left, - ) - : AppText( - TranslationBase.of(context) - .verifyFingerprint2, - fontSize: - SizeConfig.textMultiplier * 2.5, - textAlign: TextAlign.left, + child: user != null && isMoreOption == false + ? Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/habib-logo.png', + height: 80, + width: 80, + ), + AppText( + TranslationBase.of(context) + .welcomeBack + + ' ' + + user.name, + fontSize: SizeConfig.textMultiplier * 4, + ), + AppText( + TranslationBase.of(context).accountInfo, + fontSize: SizeConfig.textMultiplier * 3, + ), + Card( + color: Colors.grey[300], + child: Row( + children: [ + Expanded( + child: ListTile( + title: Text( + TranslationBase.of(context) + .lastLoginAt, + textAlign: TextAlign.center, + ), + subtitle: Text( + formatDate(DateUtil + .convertStringToDate( + user.editedOn)), + textAlign: + TextAlign.center), + )), + Expanded( + child: ListTile( + title: Text( + TranslationBase.of(context) + .lastLoginWith, + textAlign: + TextAlign.center), + subtitle: Text( + getType(user.logInType, + context), + textAlign: + TextAlign.center), + )) + ], + )) + ], + ) + : Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/habib-logo.png', + height: 80, + width: 80, ), - ])), - Expanded( - flex: 4, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - onlySMSBox == false - ? Row( + this.onlySMSBox == false + ? AppText( + TranslationBase.of(context) + .verifyLoginWith, + fontSize: + SizeConfig.textMultiplier * + 3.5, + textAlign: TextAlign.left, + ) + : AppText( + TranslationBase.of(context) + .verifyFingerprint2, + fontSize: + SizeConfig.textMultiplier * + 2.5, + textAlign: TextAlign.left, + ), + ])), + user != null && isMoreOption == false + ? Expanded( + flex: 2, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + child: InkWell( + onTap: () => { + authenticateUser( + 3, + BiometricType + .face.index) + }, + child: getButton( + user.logInType))), + Expanded(child: getButton(5)) + ]) + ])) + : Expanded( + flex: 4, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + onlySMSBox == false + ? Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded(child: getButton(3)), + Expanded(child: getButton(2)) + ], + ) + : SizedBox(), + Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Expanded( - child: InkWell( - onTap: () => { - authenticateUser( - 3, - BiometricType - .face.index) - }, - child: RoundedContainer( - backgroundColor: - BiometricType.face - .index == - 1 - ? Colors.white - : Colors.white - .withOpacity( - .7), - borderColor: Colors.grey, - showBorder: true, - child: Padding( - padding: - EdgeInsets.fromLTRB( - 20, 10, 20, 10), - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - children: [ - Image.asset( - 'assets/images/login/101.png', - height: SizeConfig - .imageSizeMultiplier * - 13, - width: SizeConfig - .imageSizeMultiplier * - 16, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of( - context) - .verifyFaceID, - fontSize: SizeConfig - .textMultiplier * - 2, - ) - ], - ), - )))), - Expanded( - child: InkWell( - onTap: () => { - authenticateUser( - 2, - BiometricType - .fingerprint - .index) - }, - child: RoundedContainer( - backgroundColor: - BiometricType - .fingerprint - .index == - 1 - ? Colors.white - : Colors.white - .withOpacity( - .7), - borderColor: Colors.grey, - showBorder: true, - child: Padding( - padding: - EdgeInsets.fromLTRB( - 25, 10, 25, 10), - child: Column( - children: [ - Image.asset( - 'assets/images/login/102.png', - height: SizeConfig - .imageSizeMultiplier * - 13, - width: SizeConfig - .imageSizeMultiplier * - 16, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of( - context) - .verifyFingerprint, - fontSize: SizeConfig - .textMultiplier * - 2, - ) - ], - ), - )))) + Expanded(child: getButton(1)), + Expanded(child: getButton(4)) ], - ) - : SizedBox(), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: InkWell( - onTap: () => - {authenticateUser(1, true)}, - child: RoundedContainer( - borderColor: Colors.grey, - showBorder: true, - child: Padding( - padding: EdgeInsets.fromLTRB( - 20, 10, 20, 10), - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - children: [ - Image.asset( - 'assets/images/login/103.png', - height: SizeConfig - .imageSizeMultiplier * - 13, - width: SizeConfig - .imageSizeMultiplier * - 16, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of( - context) - .verifySMS, - fontSize: SizeConfig - .textMultiplier * - 2, - ) - ], - ), - )))), - Expanded( - child: InkWell( - onTap: () => - {authenticateUser(4, true)}, - child: RoundedContainer( - borderColor: Colors.grey, - showBorder: true, - child: Padding( - padding: EdgeInsets.fromLTRB( - 25, 10, 25, 10), - child: Column( - children: [ - Image.asset( - 'assets/images/login/104.png', - height: SizeConfig - .imageSizeMultiplier * - 13, - width: SizeConfig - .imageSizeMultiplier * - 16, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of( - context) - .verifyWhatsApp, - fontSize: SizeConfig - .textMultiplier * - 2, - ) - ], - ), - )))) - ], - ), - ]), - ), + ), + ]), + ), Expanded( flex: 1, child: Column( @@ -369,27 +288,50 @@ class _ConfirmLogin extends State { loginWithSMS(type, isActive) { //if (!el.disabled) { - if (this.user != null && this.registerd_data != null) { + if (this.user != null && this.registerd_data == null) { this.checkUserAuthentication(type); } else { if (this.loginTokenID != null) { - this.sendActivationCode(type); + Future.delayed(Duration(seconds: 1), () { + this.sendActivationCode(type); + }); } else { this.checkUserAuthentication(type); } } } - checkUserAuthentication(type) {} + checkUserAuthentication(type) { + showLoader(true); + var req = getCommonRequest(); + var request = CheckPatientAuthenticationReq.fromJson(req.toJson()); + + sharedPref.setObject(REGISTER_DATA_FOR_REGISTER, request); + authService.checkPatientAuthentication(request).then((value) => { + if (value['isSMSSent']) + { + sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), + this.loginTokenID = value['LogInTokenID'], + sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), + Future.delayed(Duration(seconds: 1), () { + this.sendActivationCode(type); + }) + } + else + { + if (value['IsAuthenticated']) {this.checkActivationCode()} + } + }); + } sendActivationCode(type) { var request = this.getCommonRequest(); loading(true); this.authService.sendActivationCode(request).then((result) => { - if (result['isSMSSent'] == true) + if (result != null && result['isSMSSent'] == true) {loading(false), this.startSMSService(type)} else - {} + {loading(false)} }); } @@ -457,30 +399,43 @@ class _ConfirmLogin extends State { }); } + setUser() async { + user = SelectDeviceIMEIRES.fromJson( + await sharedPref.getObject(IMEI_USER_DATA)); + } + setDefault() async { // this.user = this.cs.sharedService.getSharedData( // AuthenticationService.IMEI_USER_DATA, // false // ); - this.registerd_data = CheckPatientAuthenticationReq.fromJson( - await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN)); + setState(() { + setUser(); + }); + if (await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN) != null) { + this.registerd_data = CheckPatientAuthenticationReq.fromJson( + await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN)); + } this.mobileNumber = this.registerd_data != null ? this.registerd_data.patientMobileNumber - : int.parse(this.user.Mobile); + : int.parse(this.user.mobile); this.zipCode = this.registerd_data != null ? this.registerd_data.zipCode - : this.user.OutSA ? "971" : "966"; + : this.user.outSA == true ? "971" : "966"; this.patientOutSA = this.registerd_data != null ? this.registerd_data.zipCode == "966" ? 0 : 1 - : this.user.OutSA; + : this.user.outSA; if (this.registerd_data != null) { this.loginTokenID = await sharedPref.getString(LOGIN_TOKEN_ID); this.loginType = this.registerd_data.searchType; } this.deviceToken = await sharedPref.getString(PUSH_TOKEN); - this.lastLogin = await sharedPref.getInt( - LAST_LOGIN); //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN); + this.lastLogin = await sharedPref.getInt(LAST_LOGIN) != null + ? await sharedPref.getInt(LAST_LOGIN) + : user.logInType; + + //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN); } getCommonRequest() { @@ -488,42 +443,54 @@ class _ConfirmLogin extends State { request.patientMobileNumber = this.mobileNumber; request.mobileNo = '0' + this.mobileNumber.toString(); request.deviceToken = this.deviceToken; - request.projectOutSA = this.patientOutSA; + request.projectOutSA = this.patientOutSA == true ? 1 : 0; request.loginType = this.selectedOption; request.oTPSendType = this.selectedOption == 1 ? 1 : 2; request.zipCode = this.zipCode; request.isRegister = false; request.logInTokenID = this.loginTokenID ?? ""; + if (this.registerd_data != null) { - request.searchType = this.registerd_data.searchType == 1 - ? this.registerd_data.searchType - : 1; - request.patientID = this.registerd_data.patientID != 0 - ? this.registerd_data.patientID - : 0; - request.patientIdentificationID = - request.nationalID = this.registerd_data.patientIdentificationID; + request.searchType = this.registerd_data.searchType ?? 1; + request.patientID = this.registerd_data.patientID ?? 0; + request.patientIdentificationID = request.nationalID = + this.registerd_data.patientIdentificationID ?? '0'; } else { - request.searchType = request.searchType == 1 ? request.searchType : 2; - request.patientID = int.parse(this.user.PatientID); - request.patientID = request.nationalID = - request.nationalID != null ? request.nationalID : 0; + request.searchType = request.searchType ?? 2; + request.patientID = this.user.patientID ?? 0; + request.nationalID = request.nationalID ?? '0'; + request.patientIdentificationID = request.patientIdentificationID ?? '0'; } + request.deviceTypeID = request.searchType; return request; } checkActivationCode({value}) { SMSOTP.showLoadingDialog(context, true); var request = this.getCommonRequest().toJson(); - this.authService.checkActivationCode(request, value).then((result) => { - this.userData = - result.list, //AuthenticatedUser.fromJson(result['List'][0]), - this.sharedPref.setObject(USER_PROFILE, result.list), - this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), - this.sharedPref.setString(TOKEN, result.authenticationTokenID), - this.checkIfUserAgreedBefore(result), - Navigator.of(context).pop(), - SMSOTP.showLoadingDialog(context, false), + + this.authService.checkActivationCode(request, value: value).then((result) => + { + if (result != null) + { + result = CheckActivationCode.fromJson(result), + + this.userData = + result.list, //AuthenticatedUser.fromJson(result['List'][0]), + this.sharedPref.setObject(USER_PROFILE, result.list), + this.loginTokenID = result.logInTokenID, + this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), + this.sharedPref.setString(TOKEN, result.authenticationTokenID), + this.checkIfUserAgreedBefore(result), + Navigator.of(context).pop(), + SMSOTP.showLoadingDialog(context, false), + } + else + { + AppToast.showErrorToast(message: 'Please Enter Valid Code'), + Navigator.of(context).pop(), + SMSOTP.showLoadingDialog(context, false) + } }); } @@ -580,4 +547,185 @@ class _ConfirmLogin extends State { isLoading = flag; }); } + + Widget getButton(flag) { + switch (flag) { + case 4: + return InkWell( + onTap: () => {authenticateUser(4, true)}, + child: RoundedContainer( + borderColor: Colors.grey, + showBorder: true, + child: Padding( + padding: EdgeInsets.fromLTRB(25, 10, 25, 10), + child: Column( + children: [ + Image.asset( + 'assets/images/login/104.png', + height: SizeConfig.imageSizeMultiplier * 13, + width: SizeConfig.imageSizeMultiplier * 16, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifyWhatsApp, + fontSize: SizeConfig.textMultiplier * 2, + ) + ], + ), + ))); + break; + case 1: + return InkWell( + onTap: () => {authenticateUser(1, true)}, + child: RoundedContainer( + borderColor: Colors.grey, + showBorder: true, + child: Padding( + padding: EdgeInsets.fromLTRB(20, 10, 20, 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + 'assets/images/login/103.png', + height: SizeConfig.imageSizeMultiplier * 13, + width: SizeConfig.imageSizeMultiplier * 16, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifySMS, + fontSize: SizeConfig.textMultiplier * 2, + ) + ], + ), + ))); + break; + case 2: + return InkWell( + onTap: () => {authenticateUser(2, BiometricType.fingerprint.index)}, + child: RoundedContainer( + backgroundColor: BiometricType.fingerprint.index == 1 + ? Colors.white + : Colors.white.withOpacity(.7), + borderColor: Colors.grey, + showBorder: true, + child: Padding( + padding: EdgeInsets.fromLTRB(25, 10, 25, 10), + child: Column( + children: [ + Image.asset( + 'assets/images/login/102.png', + height: SizeConfig.imageSizeMultiplier * 13, + width: SizeConfig.imageSizeMultiplier * 16, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifyFingerprint, + fontSize: SizeConfig.textMultiplier * 2, + ) + ], + ), + ))); + break; + case 3: + return InkWell( + onTap: () => {authenticateUser(3, BiometricType.face.index)}, + child: RoundedContainer( + backgroundColor: BiometricType.face.index == 1 + ? Colors.white + : Colors.white.withOpacity(.7), + borderColor: Colors.grey, + showBorder: true, + child: Padding( + padding: EdgeInsets.fromLTRB(20, 10, 20, 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + 'assets/images/login/101.png', + height: SizeConfig.imageSizeMultiplier * 13, + width: SizeConfig.imageSizeMultiplier * 16, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifyFaceID, + fontSize: SizeConfig.textMultiplier * 2, + ) + ], + ), + ))); + break; + + default: + return InkWell( + onTap: () => { + setState(() { + isMoreOption = true; + }) + }, + child: RoundedContainer( + backgroundColor: BiometricType.fingerprint.index == 1 + ? Colors.white + : Colors.white.withOpacity(.7), + borderColor: Colors.grey, + showBorder: true, + child: Padding( + padding: EdgeInsets.fromLTRB(0, 10, 0, 5), + child: Column( + children: [ + Image.asset( + 'assets/images/login/more_icon.png', + height: SizeConfig.imageSizeMultiplier * 13, + width: SizeConfig.imageSizeMultiplier * 16, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).moreVerification, + fontSize: SizeConfig.textMultiplier * 2, + textAlign: TextAlign.center, + ) + ], + ), + ))); + } + } + + getType(type, context) { + switch (type) { + case 1: + return TranslationBase.of(context).verifySMS; + break; + case 2: + return TranslationBase.of(context).verifyFingerprint; + break; + case 3: + return TranslationBase.of(context).verifyFaceID; + break; + case 4: + return TranslationBase.of(context).verifyWhatsApp; + break; + default: + return TranslationBase.of(context).verifySMS; + break; + } + } + + formatDate(date) { + return DateFormat('MMM dd, yyy, kk:mm').format(date); + } + + showLoader(bool isTrue) { + setState(() { + isLoading = isTrue; + }); + } } diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index b0f9a1fd..5d43deb8 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -1,7 +1,10 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_request.dart'; +import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart'; import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; +import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart'; import 'package:diplomaticquarterapp/pages/login/login-type.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; import 'package:diplomaticquarterapp/routes.dart'; @@ -18,6 +21,7 @@ import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_pro import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; class Login extends StatefulWidget { @override @@ -34,6 +38,12 @@ class _Login extends State { final authService = new AuthProvider(); var sharedPref = new AppSharedPreferences(); bool isLoading = false; + + @override + void initState() { + super.initState(); + } + @override Widget build(BuildContext context) { return AppScaffold( @@ -164,12 +174,44 @@ class _Login extends State { } else { - if (value.IsAuthenticated) {this.checkActivationCode()} + if (value['IsAuthenticated']) {this.checkActivationCode()} } }); } - checkActivationCode() {} + checkActivationCode({code}) async { + Map request = {}; + // request.logInTokenID = await sharedPref.getString(LOGIN_TOKEN_ID); + // request.activationCode = code ?? "0000"; + // request.isSilentLogin = code != null ? false : true; + request['PatientMobileNumber'] = int.parse(mobileNo); + request['ZipCode'] = countryCode; + request['SearchType'] = loginType; + request['LoginType'] = loginType; + if (this.loginType == 1) { + request['PatientIdentificationID'] = this.nationalIDorFile.text; + request['PatientID'] = 0; + } else { + request['PatientIdentificationID'] = ''; + request['PatientID'] = int.parse(nationalIDorFile.text); + } + // request.isRegister = false; + this + .authService + .checkActivationCode(request, value: code) + .then((result) => { + result = CheckActivationCode.fromJson(result), + this.sharedPref.setObject(USER_PROFILE, result.list), + this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), + this.sharedPref.setString(TOKEN, result.authenticationTokenID), + //this.checkIfUserAgreedBefore(result), + Navigator.of(context).pushNamed( + HOME, + ) + // SMSOTP.showLoadingDialog(context, false), + }); + } + showLoader(bool isTrue) { setState(() { isLoading = isTrue; diff --git a/lib/pages/login/welcome.dart b/lib/pages/login/welcome.dart index 1f2c0474..b4b05900 100644 --- a/lib/pages/login/welcome.dart +++ b/lib/pages/login/welcome.dart @@ -1,14 +1,30 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; +import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:diplomaticquarterapp/routes.dart'; -class WelcomeLogin extends StatelessWidget { +class WelcomeLogin extends StatefulWidget { @override + _WelcomeLogin createState() => _WelcomeLogin(); +} + +class _WelcomeLogin extends State { + bool isLoading = true; + @override + void initState() { + isLoading = true; + // checkUser(context); + super.initState(); + } + Widget build(BuildContext context) { return AppScaffold( appBarTitle: TranslationBase.of(context).welcome, diff --git a/lib/routes.dart b/lib/routes.dart index 0ee2364b..91126829 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -5,6 +5,7 @@ import 'package:diplomaticquarterapp/pages/login/welcome.dart'; import 'package:diplomaticquarterapp/pages/login/login-type.dart'; import 'package:diplomaticquarterapp/pages/login/login.dart'; import 'package:diplomaticquarterapp/pages/login/register.dart'; +import 'package:flutter/material.dart'; const String INIT_ROUTE = '/'; const String ROOT = 'root'; diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index 0e35964d..6bb7284b 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -213,7 +213,7 @@ class AuthProvider with ChangeNotifier { } } - Future checkActivationCode(request, value) async { + Future checkActivationCode(request, {value}) async { var neRequest = CheckActivationCodeReq.fromJson(request); neRequest.activationCode = value ?? "0000"; neRequest.isSilentLogin = value != null ? false : true; @@ -225,18 +225,20 @@ class AuthProvider with ChangeNotifier { neRequest.languageID = 2; neRequest.deviceTypeID = DeviceTypeID; neRequest.patientOutSA = neRequest.zipCode == '966' ? 0 : 1; + neRequest.projectOutSA = neRequest.zipCode == '966' ? 0 : 1; neRequest.isDentalAllowedBackend = false; try { dynamic localRes; await new BaseAppClient().post(CHECK_ACTIVATION_CODE, onSuccess: (dynamic response, int statusCode) { - localRes = CheckActivationCode.fromJson(response); + localRes = response; //CheckActivationCode.fromJson(); }, onFailure: (String error, int statusCode) { throw error; }, body: neRequest.toJson()); return Future.value(localRes); } catch (error) { - print(error); + Future.error(error); + throw error; } } diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 2beb338d..b10b6a4e 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -160,6 +160,12 @@ class TranslationBase { localizedValues['notification'][locale.languageCode]; String get appsetting => localizedValues['app-settings'][locale.languageCode]; String get rateApp => localizedValues['rate-app'][locale.languageCode]; + String get moreVerification => + localizedValues['more-verify'][locale.languageCode]; + String get welcomeBack => + localizedValues['welcome-back'][locale.languageCode]; + String get accountInfo => + localizedValues['account-info'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate { diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index b01bb19e..260f5851 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -41,7 +41,7 @@ class _AppDrawerState extends State { padding: EdgeInsets.zero, children: [ Container( - height: SizeConfig.screenHeight * .25, + height: SizeConfig.screenHeight * .30, child: InkWell( child: DrawerHeader( child: Column( @@ -168,9 +168,7 @@ class _AppDrawerState extends State { TranslationBase.of(context).loginregister, Icons.lock_open), onTap: () { - Navigator.of(context).pushNamed( - WELCOME_LOGIN, - ); + login(); }, ), ], @@ -214,17 +212,35 @@ class _AppDrawerState extends State { } checkUserData() async { - var data = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(USER_PROFILE)); - setState(() { - this.user = data; - print(this.user); - }); + if (await this.sharedPref.getObject(USER_PROFILE) != null) { + var data = AuthenticatedUser.fromJson( + await this.sharedPref.getObject(USER_PROFILE)); + setState(() { + this.user = data; + print(this.user); + }); + } } logout() async { - this.sharedPref.remove(USER_PROFILE); + // this.sharedPref.remove(USER_PROFILE); + // this.sharedPref.remove(IMEI_USER_DATA); + // this.sharedPref.remove(TOKEN); + // this.sharedPref.remove(LOGIN_TOKEN_ID); + await sharedPref.clear(); + this.user = null; Navigator.of(context).pushNamed(HOME); } + + login() async { + var data = await sharedPref.getObject(IMEI_USER_DATA); + if (data != null) { + Navigator.of(context).pushNamed(CONFIRM_LOGIN); + } else { + Navigator.of(context).pushNamed( + WELCOME_LOGIN, + ); + } + } } diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 062b40d8..dfad1791 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -1,4 +1,5 @@ import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import '../progress_indicator/app_loader_widget.dart'; import 'arrow_back.dart'; @@ -50,6 +51,9 @@ class AppScaffold extends StatelessWidget { color: Colors.white, onPressed: () { // TODO add navigator to home page + Navigator.of(context).pushNamed( + HOME, + ); }, ), ], diff --git a/lib/widgets/otp/sms-popup.dart b/lib/widgets/otp/sms-popup.dart index 75a2eda7..da244324 100644 --- a/lib/widgets/otp/sms-popup.dart +++ b/lib/widgets/otp/sms-popup.dart @@ -74,7 +74,7 @@ class SMSOTP { ? Image.asset('assets/images/login/103.png') : Image.asset('assets/images/login/104.png'), Padding( - padding: EdgeInsets.only(top: 20), + padding: EdgeInsets.only(top: 5), child: AppText( TranslationBase.of(context).verificationMessage + ' XXXXXX' + From 0bc529f420940027fc7d52f8d9549e762eef1c09 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Sun, 9 Aug 2020 09:29:05 +0300 Subject: [PATCH 3/4] login changes --- lib/config/config.dart | 14 +- lib/config/localized_values.dart | 1 + lib/config/shared_pref_kay.dart | 1 + lib/core/service/client/base_app_client.dart | 4 +- .../check_user_status_reponse.dart | 316 +++++++++++++++++ .../Authentication/check_user_status_req.dart | 60 ++++ .../checkpatient_for_registration.dart | 72 ++++ .../register_info_response.dart | 316 +++++++++++++++++ lib/pages/login/confirm-login.dart | 65 ++-- lib/pages/login/login.dart | 18 +- lib/pages/login/register-info.dart | 132 +++++++ lib/pages/login/register.dart | 325 +++++++++++++----- lib/routes.dart | 5 +- .../authentication/auth_provider.dart | 76 +++- lib/uitl/translations_delegate_base.dart | 2 + lib/uitl/utils.dart | 12 + lib/widgets/otp/sms-popup.dart | 3 +- 17 files changed, 1267 insertions(+), 155 deletions(-) create mode 100644 lib/models/Authentication/check_user_status_reponse.dart create mode 100644 lib/models/Authentication/check_user_status_req.dart create mode 100644 lib/models/Authentication/checkpatient_for_registration.dart create mode 100644 lib/models/Authentication/register_info_response.dart create mode 100644 lib/pages/login/register-info.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index 643a2ec9..4bbe7bdb 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -4,7 +4,7 @@ import 'dart:io'; const MAX_SMALL_SCREEN = 660; -const BASE_URL = 'https://hmgwebservices.com/Services'; +const BASE_URL = 'https://uat.hmgwebservices.com/Services'; const GET_PROJECT = '/Lists.svc/REST/GetProject'; @@ -13,12 +13,12 @@ const GET_MY_DOCTOR = '/Doctors.svc/REST/GetPatientDoctorAppointmentResult'; const GET_DOCTOR_PROFILE = '/Doctors.svc/REST/GetDocProfiles'; const GET_DOCTOR_RATING = '/Doctors.svc/REST/dr_GetAvgDoctorRating'; - ///Prescriptions const PRESCRIPTIONS = '/Patients.svc/REST/GetPrescriptionApptList'; -const GET_PRESCRIPTIONS_ALL_ORDERS = '/Patients.svc/REST/PatientER_GetPatientAllPresOrders'; -const GET_PRESCRIPTION_REPORT = '/Patients.svc/REST/INP_GetPrescriptionReport'; -const SEND_PRESCRIPTION_EMAIL = '/Notifications.svc/REST/SendPrescriptionEmail'; +const GET_PRESCRIPTIONS_ALL_ORDERS = + '/Patients.svc/REST/PatientER_GetPatientAllPresOrders'; +const GET_PRESCRIPTION_REPORT = '/Patients.svc/REST/INP_GetPrescriptionReport'; +const SEND_PRESCRIPTION_EMAIL = '/Notifications.svc/REST/SendPrescriptionEmail'; //const BASE_URL = 'https://hmgwebservices.com/'; // Production Environment //const BASE_URL = 'https://uat.hmgwebservices.com/Services'; // UAT Environment @@ -34,7 +34,7 @@ const GENERAL_ID = 'Cs2020@2016\$2958'; const IP_ADDRESS = '10.20.10.20'; const VERSION_ID = 5.5; var DeviceTypeID = Platform.isIOS ? 1 : 2; - +const LANGUAGE_ID = 2; const GET_PHARMCY_ITEMS = "/Lists.svc/REST/GetPharmcyItems_Region"; const GET_PHARMACY_LIST = "/Patients.svc/REST/GetPharmcyList"; @@ -59,5 +59,3 @@ class AppGlobal { return request; } } - - diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 2c3a4c43..112b3561 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -137,4 +137,5 @@ const Map> localizedValues = { "en": "Would you like to login with current username?", "ar": "هل ترغب في تسجيل الدخول باسم المستخدم الحالي؟" }, + "another-acc": {"en": "Use Another Account", "ar": "استخدم حسابا آخر"}, }; diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart index cbf523bd..53fa08dd 100644 --- a/lib/config/shared_pref_kay.dart +++ b/lib/config/shared_pref_kay.dart @@ -9,3 +9,4 @@ const LAST_LOGIN = 'last-login'; const ONLY_SMS = 'only-sms'; const AUTH_DATA = 'auth-data'; const IMEI_USER_DATA = 'imei-user-data'; +const NHIC_DATA = 'nhic-data'; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index 00e57440..95dee764 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -46,12 +46,14 @@ class BaseAppClient { if (!parsed['IsAuthenticated']) { if (parsed['isSMSSent'] == true) { onSuccess(parsed, statusCode); + } else if (parsed['MessageStatus'] == 1) { + onSuccess(parsed, statusCode); } else { logout(); } // await helpers.logout(); //helpers.showErrorToast('Your session expired Please login agian'); - var asd =""; + // var asd = ""; // TODO create logout fun } else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) { diff --git a/lib/models/Authentication/check_user_status_reponse.dart b/lib/models/Authentication/check_user_status_reponse.dart new file mode 100644 index 00000000..342eaad0 --- /dev/null +++ b/lib/models/Authentication/check_user_status_reponse.dart @@ -0,0 +1,316 @@ +class CheckUserStatusResponse { + Null date; + int languageID; + int serviceName; + Null time; + Null androidLink; + Null authenticationTokenID; + Null data; + bool dataw; + int dietType; + Null errorCode; + Null errorEndUserMessage; + Null errorEndUserMessageN; + Null errorMessage; + int errorType; + int foodCategory; + Null iOSLink; + bool isAuthenticated; + int mealOrderStatus; + int mealType; + int messageStatus; + int numberOfResultRecords; + Null patientBlodType; + Null successMsg; + Null successMsgN; + Null accessTokenObject; + int age; + Null clientIdentifierId; + int createdBy; + String dateOfBirth; + String firstNameAr; + String firstNameEn; + String gender; + Null genderAr; + Null genderEn; + String healthId; + String idNumber; + String idType; + bool isHijri; + int isInstertedOrUpdated; + int isNull; + int isPatientExistNHIC; + String lastNameAr; + String lastNameEn; + Null listActiveAccessToken; + String maritalStatus; + String maritalStatusCode; + String nationality; + String nationalityCode; + String occupation; + String patientStatus; + String placeofBirth; + Null practitionerStatusCode; + Null practitionerStatusDescAr; + Null practitionerStatusDescEn; + String secondNameAr; + String secondNameEn; + String thirdNameAr; + String thirdNameEn; + Null accessToken; + int categoryCode; + Null categoryNameAr; + Null categoryNameEn; + int constraintCode; + Null constraintNameAr; + Null constraintNameEn; + Null content; + Null licenseExpiryDate; + Null licenseIssuedDate; + Null licenseStatusCode; + Null licenseStatusDescAr; + Null licenseStatusDescEn; + Null organizations; + Null registrationNumber; + int specialtyCode; + Null specialtyNameAr; + Null specialtyNameEn; + + CheckUserStatusResponse( + {this.date, + this.languageID, + this.serviceName, + this.time, + this.androidLink, + this.authenticationTokenID, + this.data, + this.dataw, + this.dietType, + this.errorCode, + this.errorEndUserMessage, + this.errorEndUserMessageN, + this.errorMessage, + this.errorType, + this.foodCategory, + this.iOSLink, + this.isAuthenticated, + this.mealOrderStatus, + this.mealType, + this.messageStatus, + this.numberOfResultRecords, + this.patientBlodType, + this.successMsg, + this.successMsgN, + this.accessTokenObject, + this.age, + this.clientIdentifierId, + this.createdBy, + this.dateOfBirth, + this.firstNameAr, + this.firstNameEn, + this.gender, + this.genderAr, + this.genderEn, + this.healthId, + this.idNumber, + this.idType, + this.isHijri, + this.isInstertedOrUpdated, + this.isNull, + this.isPatientExistNHIC, + this.lastNameAr, + this.lastNameEn, + this.listActiveAccessToken, + this.maritalStatus, + this.maritalStatusCode, + this.nationality, + this.nationalityCode, + this.occupation, + this.patientStatus, + this.placeofBirth, + this.practitionerStatusCode, + this.practitionerStatusDescAr, + this.practitionerStatusDescEn, + this.secondNameAr, + this.secondNameEn, + this.thirdNameAr, + this.thirdNameEn, + this.accessToken, + this.categoryCode, + this.categoryNameAr, + this.categoryNameEn, + this.constraintCode, + this.constraintNameAr, + this.constraintNameEn, + this.content, + this.licenseExpiryDate, + this.licenseIssuedDate, + this.licenseStatusCode, + this.licenseStatusDescAr, + this.licenseStatusDescEn, + this.organizations, + this.registrationNumber, + this.specialtyCode, + this.specialtyNameAr, + this.specialtyNameEn}); + + CheckUserStatusResponse.fromJson(Map json) { + date = json['Date']; + languageID = json['LanguageID']; + serviceName = json['ServiceName']; + time = json['Time']; + androidLink = json['AndroidLink']; + authenticationTokenID = json['AuthenticationTokenID']; + data = json['Data']; + dataw = json['Dataw']; + dietType = json['DietType']; + errorCode = json['ErrorCode']; + errorEndUserMessage = json['ErrorEndUserMessage']; + errorEndUserMessageN = json['ErrorEndUserMessageN']; + errorMessage = json['ErrorMessage']; + errorType = json['ErrorType']; + foodCategory = json['FoodCategory']; + iOSLink = json['IOSLink']; + isAuthenticated = json['IsAuthenticated']; + mealOrderStatus = json['MealOrderStatus']; + mealType = json['MealType']; + messageStatus = json['MessageStatus']; + numberOfResultRecords = json['NumberOfResultRecords']; + patientBlodType = json['PatientBlodType']; + successMsg = json['SuccessMsg']; + successMsgN = json['SuccessMsgN']; + accessTokenObject = json['AccessTokenObject']; + age = json['Age']; + clientIdentifierId = json['ClientIdentifierId']; + createdBy = json['CreatedBy']; + dateOfBirth = json['DateOfBirth']; + firstNameAr = json['FirstNameAr']; + firstNameEn = json['FirstNameEn']; + gender = json['Gender']; + genderAr = json['GenderAr']; + genderEn = json['GenderEn']; + healthId = json['HealthId']; + idNumber = json['IdNumber']; + idType = json['IdType']; + isHijri = json['IsHijri']; + isInstertedOrUpdated = json['IsInstertedOrUpdated']; + isNull = json['IsNull']; + isPatientExistNHIC = json['IsPatientExistNHIC']; + lastNameAr = json['LastNameAr']; + lastNameEn = json['LastNameEn']; + listActiveAccessToken = json['List_ActiveAccessToken']; + maritalStatus = json['MaritalStatus']; + maritalStatusCode = json['MaritalStatusCode']; + nationality = json['Nationality']; + nationalityCode = json['NationalityCode']; + occupation = json['Occupation']; + patientStatus = json['PatientStatus']; + placeofBirth = json['PlaceofBirth']; + practitionerStatusCode = json['PractitionerStatusCode']; + practitionerStatusDescAr = json['PractitionerStatusDescAr']; + practitionerStatusDescEn = json['PractitionerStatusDescEn']; + secondNameAr = json['SecondNameAr']; + secondNameEn = json['SecondNameEn']; + thirdNameAr = json['ThirdNameAr']; + thirdNameEn = json['ThirdNameEn']; + accessToken = json['accessToken']; + categoryCode = json['categoryCode']; + categoryNameAr = json['categoryNameAr']; + categoryNameEn = json['categoryNameEn']; + constraintCode = json['constraintCode']; + constraintNameAr = json['constraintNameAr']; + constraintNameEn = json['constraintNameEn']; + content = json['content']; + licenseExpiryDate = json['licenseExpiryDate']; + licenseIssuedDate = json['licenseIssuedDate']; + licenseStatusCode = json['licenseStatusCode']; + licenseStatusDescAr = json['licenseStatusDescAr']; + licenseStatusDescEn = json['licenseStatusDescEn']; + organizations = json['organizations']; + registrationNumber = json['registrationNumber']; + specialtyCode = json['specialtyCode']; + specialtyNameAr = json['specialtyNameAr']; + specialtyNameEn = json['specialtyNameEn']; + } + + Map toJson() { + final Map data = new Map(); + data['Date'] = this.date; + data['LanguageID'] = this.languageID; + data['ServiceName'] = this.serviceName; + data['Time'] = this.time; + data['AndroidLink'] = this.androidLink; + data['AuthenticationTokenID'] = this.authenticationTokenID; + data['Data'] = this.data; + data['Dataw'] = this.dataw; + data['DietType'] = this.dietType; + data['ErrorCode'] = this.errorCode; + data['ErrorEndUserMessage'] = this.errorEndUserMessage; + data['ErrorEndUserMessageN'] = this.errorEndUserMessageN; + data['ErrorMessage'] = this.errorMessage; + data['ErrorType'] = this.errorType; + data['FoodCategory'] = this.foodCategory; + data['IOSLink'] = this.iOSLink; + data['IsAuthenticated'] = this.isAuthenticated; + data['MealOrderStatus'] = this.mealOrderStatus; + data['MealType'] = this.mealType; + data['MessageStatus'] = this.messageStatus; + data['NumberOfResultRecords'] = this.numberOfResultRecords; + data['PatientBlodType'] = this.patientBlodType; + data['SuccessMsg'] = this.successMsg; + data['SuccessMsgN'] = this.successMsgN; + data['AccessTokenObject'] = this.accessTokenObject; + data['Age'] = this.age; + data['ClientIdentifierId'] = this.clientIdentifierId; + data['CreatedBy'] = this.createdBy; + data['DateOfBirth'] = this.dateOfBirth; + data['FirstNameAr'] = this.firstNameAr; + data['FirstNameEn'] = this.firstNameEn; + data['Gender'] = this.gender; + data['GenderAr'] = this.genderAr; + data['GenderEn'] = this.genderEn; + data['HealthId'] = this.healthId; + data['IdNumber'] = this.idNumber; + data['IdType'] = this.idType; + data['IsHijri'] = this.isHijri; + data['IsInstertedOrUpdated'] = this.isInstertedOrUpdated; + data['IsNull'] = this.isNull; + data['IsPatientExistNHIC'] = this.isPatientExistNHIC; + data['LastNameAr'] = this.lastNameAr; + data['LastNameEn'] = this.lastNameEn; + data['List_ActiveAccessToken'] = this.listActiveAccessToken; + data['MaritalStatus'] = this.maritalStatus; + data['MaritalStatusCode'] = this.maritalStatusCode; + data['Nationality'] = this.nationality; + data['NationalityCode'] = this.nationalityCode; + data['Occupation'] = this.occupation; + data['PatientStatus'] = this.patientStatus; + data['PlaceofBirth'] = this.placeofBirth; + data['PractitionerStatusCode'] = this.practitionerStatusCode; + data['PractitionerStatusDescAr'] = this.practitionerStatusDescAr; + data['PractitionerStatusDescEn'] = this.practitionerStatusDescEn; + data['SecondNameAr'] = this.secondNameAr; + data['SecondNameEn'] = this.secondNameEn; + data['ThirdNameAr'] = this.thirdNameAr; + data['ThirdNameEn'] = this.thirdNameEn; + data['accessToken'] = this.accessToken; + data['categoryCode'] = this.categoryCode; + data['categoryNameAr'] = this.categoryNameAr; + data['categoryNameEn'] = this.categoryNameEn; + data['constraintCode'] = this.constraintCode; + data['constraintNameAr'] = this.constraintNameAr; + data['constraintNameEn'] = this.constraintNameEn; + data['content'] = this.content; + data['licenseExpiryDate'] = this.licenseExpiryDate; + data['licenseIssuedDate'] = this.licenseIssuedDate; + data['licenseStatusCode'] = this.licenseStatusCode; + data['licenseStatusDescAr'] = this.licenseStatusDescAr; + data['licenseStatusDescEn'] = this.licenseStatusDescEn; + data['organizations'] = this.organizations; + data['registrationNumber'] = this.registrationNumber; + data['specialtyCode'] = this.specialtyCode; + data['specialtyNameAr'] = this.specialtyNameAr; + data['specialtyNameEn'] = this.specialtyNameEn; + return data; + } +} diff --git a/lib/models/Authentication/check_user_status_req.dart b/lib/models/Authentication/check_user_status_req.dart new file mode 100644 index 00000000..40dd8b49 --- /dev/null +++ b/lib/models/Authentication/check_user_status_req.dart @@ -0,0 +1,60 @@ +class CheckUserStatusRequest { + String patientIdentificationID; + String dOB; + int isHijri; + double versionID; + int channel; + int languageID; + String iPAdress; + String generalid; + int patientOutSA; + Null sessionID; + bool isDentalAllowedBackend; + int deviceTypeID; + + CheckUserStatusRequest( + {this.patientIdentificationID, + this.dOB, + this.isHijri, + this.versionID, + this.channel, + this.languageID, + this.iPAdress, + this.generalid, + this.patientOutSA, + this.sessionID, + this.isDentalAllowedBackend, + this.deviceTypeID}); + + CheckUserStatusRequest.fromJson(Map json) { + patientIdentificationID = json['PatientIdentificationID']; + dOB = json['DOB']; + isHijri = json['IsHijri']; + versionID = json['VersionID']; + channel = json['Channel']; + languageID = json['LanguageID']; + iPAdress = json['IPAdress']; + generalid = json['generalid']; + patientOutSA = json['PatientOutSA']; + sessionID = json['SessionID']; + isDentalAllowedBackend = json['isDentalAllowedBackend']; + deviceTypeID = json['DeviceTypeID']; + } + + Map toJson() { + final Map data = new Map(); + data['PatientIdentificationID'] = this.patientIdentificationID; + data['DOB'] = this.dOB; + data['IsHijri'] = this.isHijri; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['LanguageID'] = this.languageID; + data['IPAdress'] = this.iPAdress; + data['generalid'] = this.generalid; + data['PatientOutSA'] = this.patientOutSA; + data['SessionID'] = this.sessionID; + data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; + data['DeviceTypeID'] = this.deviceTypeID; + return data; + } +} diff --git a/lib/models/Authentication/checkpatient_for_registration.dart b/lib/models/Authentication/checkpatient_for_registration.dart new file mode 100644 index 00000000..420b4adb --- /dev/null +++ b/lib/models/Authentication/checkpatient_for_registration.dart @@ -0,0 +1,72 @@ +class CheckPatientForRegistration { + int patientIdentificationID; + int patientMobileNumber; + String zipCode; + double versionID; + int channel; + int languageID; + String iPAdress; + String generalid; + int patientOutSA; + Null sessionID; + bool isDentalAllowedBackend; + int deviceTypeID; + String tokenID; + int patientID; + bool isRegister; + + CheckPatientForRegistration( + {this.patientIdentificationID, + this.patientMobileNumber, + this.zipCode, + this.versionID, + this.channel, + this.languageID, + this.iPAdress, + this.generalid, + this.patientOutSA, + this.sessionID, + this.isDentalAllowedBackend, + this.deviceTypeID, + this.tokenID, + this.patientID, + this.isRegister}); + + CheckPatientForRegistration.fromJson(Map json) { + patientIdentificationID = json['PatientIdentificationID']; + patientMobileNumber = json['PatientMobileNumber']; + zipCode = json['ZipCode']; + versionID = json['VersionID']; + channel = json['Channel']; + languageID = json['LanguageID']; + iPAdress = json['IPAdress']; + generalid = json['generalid']; + patientOutSA = json['PatientOutSA']; + sessionID = json['SessionID']; + isDentalAllowedBackend = json['isDentalAllowedBackend']; + deviceTypeID = json['DeviceTypeID']; + tokenID = json['TokenID']; + patientID = json['PatientID']; + isRegister = json['isRegister']; + } + + Map toJson() { + final Map data = new Map(); + data['PatientIdentificationID'] = this.patientIdentificationID; + data['PatientMobileNumber'] = this.patientMobileNumber; + data['ZipCode'] = this.zipCode; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['LanguageID'] = this.languageID; + data['IPAdress'] = this.iPAdress; + data['generalid'] = this.generalid; + data['PatientOutSA'] = this.patientOutSA; + data['SessionID'] = this.sessionID; + data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; + data['DeviceTypeID'] = this.deviceTypeID; + data['TokenID'] = this.tokenID; + data['PatientID'] = this.patientID; + data['isRegister'] = this.isRegister; + return data; + } +} diff --git a/lib/models/Authentication/register_info_response.dart b/lib/models/Authentication/register_info_response.dart new file mode 100644 index 00000000..309a8aa9 --- /dev/null +++ b/lib/models/Authentication/register_info_response.dart @@ -0,0 +1,316 @@ +class RegisterInfoResponse { + Null date; + int languageID; + int serviceName; + Null time; + Null androidLink; + Null authenticationTokenID; + Null data; + bool dataw; + int dietType; + Null errorCode; + Null errorEndUserMessage; + Null errorEndUserMessageN; + Null errorMessage; + int errorType; + int foodCategory; + Null iOSLink; + bool isAuthenticated; + int mealOrderStatus; + int mealType; + int messageStatus; + int numberOfResultRecords; + Null patientBlodType; + Null successMsg; + Null successMsgN; + Null accessTokenObject; + int age; + Null clientIdentifierId; + int createdBy; + String dateOfBirth; + String firstNameAr; + String firstNameEn; + String gender; + Null genderAr; + Null genderEn; + String healthId; + String idNumber; + String idType; + bool isHijri; + int isInstertedOrUpdated; + int isNull; + int isPatientExistNHIC; + String lastNameAr; + String lastNameEn; + Null listActiveAccessToken; + String maritalStatus; + String maritalStatusCode; + String nationality; + String nationalityCode; + String occupation; + String patientStatus; + String placeofBirth; + Null practitionerStatusCode; + Null practitionerStatusDescAr; + Null practitionerStatusDescEn; + String secondNameAr; + String secondNameEn; + String thirdNameAr; + String thirdNameEn; + Null accessToken; + int categoryCode; + Null categoryNameAr; + Null categoryNameEn; + int constraintCode; + Null constraintNameAr; + Null constraintNameEn; + Null content; + Null licenseExpiryDate; + Null licenseIssuedDate; + Null licenseStatusCode; + Null licenseStatusDescAr; + Null licenseStatusDescEn; + Null organizations; + Null registrationNumber; + int specialtyCode; + Null specialtyNameAr; + Null specialtyNameEn; + + RegisterInfoResponse( + {this.date, + this.languageID, + this.serviceName, + this.time, + this.androidLink, + this.authenticationTokenID, + this.data, + this.dataw, + this.dietType, + this.errorCode, + this.errorEndUserMessage, + this.errorEndUserMessageN, + this.errorMessage, + this.errorType, + this.foodCategory, + this.iOSLink, + this.isAuthenticated, + this.mealOrderStatus, + this.mealType, + this.messageStatus, + this.numberOfResultRecords, + this.patientBlodType, + this.successMsg, + this.successMsgN, + this.accessTokenObject, + this.age, + this.clientIdentifierId, + this.createdBy, + this.dateOfBirth, + this.firstNameAr, + this.firstNameEn, + this.gender, + this.genderAr, + this.genderEn, + this.healthId, + this.idNumber, + this.idType, + this.isHijri, + this.isInstertedOrUpdated, + this.isNull, + this.isPatientExistNHIC, + this.lastNameAr, + this.lastNameEn, + this.listActiveAccessToken, + this.maritalStatus, + this.maritalStatusCode, + this.nationality, + this.nationalityCode, + this.occupation, + this.patientStatus, + this.placeofBirth, + this.practitionerStatusCode, + this.practitionerStatusDescAr, + this.practitionerStatusDescEn, + this.secondNameAr, + this.secondNameEn, + this.thirdNameAr, + this.thirdNameEn, + this.accessToken, + this.categoryCode, + this.categoryNameAr, + this.categoryNameEn, + this.constraintCode, + this.constraintNameAr, + this.constraintNameEn, + this.content, + this.licenseExpiryDate, + this.licenseIssuedDate, + this.licenseStatusCode, + this.licenseStatusDescAr, + this.licenseStatusDescEn, + this.organizations, + this.registrationNumber, + this.specialtyCode, + this.specialtyNameAr, + this.specialtyNameEn}); + + RegisterInfoResponse.fromJson(Map json) { + date = json['Date']; + languageID = json['LanguageID']; + serviceName = json['ServiceName']; + time = json['Time']; + androidLink = json['AndroidLink']; + authenticationTokenID = json['AuthenticationTokenID']; + data = json['Data']; + dataw = json['Dataw']; + dietType = json['DietType']; + errorCode = json['ErrorCode']; + errorEndUserMessage = json['ErrorEndUserMessage']; + errorEndUserMessageN = json['ErrorEndUserMessageN']; + errorMessage = json['ErrorMessage']; + errorType = json['ErrorType']; + foodCategory = json['FoodCategory']; + iOSLink = json['IOSLink']; + isAuthenticated = json['IsAuthenticated']; + mealOrderStatus = json['MealOrderStatus']; + mealType = json['MealType']; + messageStatus = json['MessageStatus']; + numberOfResultRecords = json['NumberOfResultRecords']; + patientBlodType = json['PatientBlodType']; + successMsg = json['SuccessMsg']; + successMsgN = json['SuccessMsgN']; + accessTokenObject = json['AccessTokenObject']; + age = json['Age']; + clientIdentifierId = json['ClientIdentifierId']; + createdBy = json['CreatedBy']; + dateOfBirth = json['DateOfBirth']; + firstNameAr = json['FirstNameAr']; + firstNameEn = json['FirstNameEn']; + gender = json['Gender']; + genderAr = json['GenderAr']; + genderEn = json['GenderEn']; + healthId = json['HealthId']; + idNumber = json['IdNumber']; + idType = json['IdType']; + isHijri = json['IsHijri']; + isInstertedOrUpdated = json['IsInstertedOrUpdated']; + isNull = json['IsNull']; + isPatientExistNHIC = json['IsPatientExistNHIC']; + lastNameAr = json['LastNameAr']; + lastNameEn = json['LastNameEn']; + listActiveAccessToken = json['List_ActiveAccessToken']; + maritalStatus = json['MaritalStatus']; + maritalStatusCode = json['MaritalStatusCode']; + nationality = json['Nationality']; + nationalityCode = json['NationalityCode']; + occupation = json['Occupation']; + patientStatus = json['PatientStatus']; + placeofBirth = json['PlaceofBirth']; + practitionerStatusCode = json['PractitionerStatusCode']; + practitionerStatusDescAr = json['PractitionerStatusDescAr']; + practitionerStatusDescEn = json['PractitionerStatusDescEn']; + secondNameAr = json['SecondNameAr']; + secondNameEn = json['SecondNameEn']; + thirdNameAr = json['ThirdNameAr']; + thirdNameEn = json['ThirdNameEn']; + accessToken = json['accessToken']; + categoryCode = json['categoryCode']; + categoryNameAr = json['categoryNameAr']; + categoryNameEn = json['categoryNameEn']; + constraintCode = json['constraintCode']; + constraintNameAr = json['constraintNameAr']; + constraintNameEn = json['constraintNameEn']; + content = json['content']; + licenseExpiryDate = json['licenseExpiryDate']; + licenseIssuedDate = json['licenseIssuedDate']; + licenseStatusCode = json['licenseStatusCode']; + licenseStatusDescAr = json['licenseStatusDescAr']; + licenseStatusDescEn = json['licenseStatusDescEn']; + organizations = json['organizations']; + registrationNumber = json['registrationNumber']; + specialtyCode = json['specialtyCode']; + specialtyNameAr = json['specialtyNameAr']; + specialtyNameEn = json['specialtyNameEn']; + } + + Map toJson() { + final Map data = new Map(); + data['Date'] = this.date; + data['LanguageID'] = this.languageID; + data['ServiceName'] = this.serviceName; + data['Time'] = this.time; + data['AndroidLink'] = this.androidLink; + data['AuthenticationTokenID'] = this.authenticationTokenID; + data['Data'] = this.data; + data['Dataw'] = this.dataw; + data['DietType'] = this.dietType; + data['ErrorCode'] = this.errorCode; + data['ErrorEndUserMessage'] = this.errorEndUserMessage; + data['ErrorEndUserMessageN'] = this.errorEndUserMessageN; + data['ErrorMessage'] = this.errorMessage; + data['ErrorType'] = this.errorType; + data['FoodCategory'] = this.foodCategory; + data['IOSLink'] = this.iOSLink; + data['IsAuthenticated'] = this.isAuthenticated; + data['MealOrderStatus'] = this.mealOrderStatus; + data['MealType'] = this.mealType; + data['MessageStatus'] = this.messageStatus; + data['NumberOfResultRecords'] = this.numberOfResultRecords; + data['PatientBlodType'] = this.patientBlodType; + data['SuccessMsg'] = this.successMsg; + data['SuccessMsgN'] = this.successMsgN; + data['AccessTokenObject'] = this.accessTokenObject; + data['Age'] = this.age; + data['ClientIdentifierId'] = this.clientIdentifierId; + data['CreatedBy'] = this.createdBy; + data['DateOfBirth'] = this.dateOfBirth; + data['FirstNameAr'] = this.firstNameAr; + data['FirstNameEn'] = this.firstNameEn; + data['Gender'] = this.gender; + data['GenderAr'] = this.genderAr; + data['GenderEn'] = this.genderEn; + data['HealthId'] = this.healthId; + data['IdNumber'] = this.idNumber; + data['IdType'] = this.idType; + data['IsHijri'] = this.isHijri; + data['IsInstertedOrUpdated'] = this.isInstertedOrUpdated; + data['IsNull'] = this.isNull; + data['IsPatientExistNHIC'] = this.isPatientExistNHIC; + data['LastNameAr'] = this.lastNameAr; + data['LastNameEn'] = this.lastNameEn; + data['List_ActiveAccessToken'] = this.listActiveAccessToken; + data['MaritalStatus'] = this.maritalStatus; + data['MaritalStatusCode'] = this.maritalStatusCode; + data['Nationality'] = this.nationality; + data['NationalityCode'] = this.nationalityCode; + data['Occupation'] = this.occupation; + data['PatientStatus'] = this.patientStatus; + data['PlaceofBirth'] = this.placeofBirth; + data['PractitionerStatusCode'] = this.practitionerStatusCode; + data['PractitionerStatusDescAr'] = this.practitionerStatusDescAr; + data['PractitionerStatusDescEn'] = this.practitionerStatusDescEn; + data['SecondNameAr'] = this.secondNameAr; + data['SecondNameEn'] = this.secondNameEn; + data['ThirdNameAr'] = this.thirdNameAr; + data['ThirdNameEn'] = this.thirdNameEn; + data['accessToken'] = this.accessToken; + data['categoryCode'] = this.categoryCode; + data['categoryNameAr'] = this.categoryNameAr; + data['categoryNameEn'] = this.categoryNameEn; + data['constraintCode'] = this.constraintCode; + data['constraintNameAr'] = this.constraintNameAr; + data['constraintNameEn'] = this.constraintNameEn; + data['content'] = this.content; + data['licenseExpiryDate'] = this.licenseExpiryDate; + data['licenseIssuedDate'] = this.licenseIssuedDate; + data['licenseStatusCode'] = this.licenseStatusCode; + data['licenseStatusDescAr'] = this.licenseStatusDescAr; + data['licenseStatusDescEn'] = this.licenseStatusDescEn; + data['organizations'] = this.organizations; + data['registrationNumber'] = this.registrationNumber; + data['specialtyCode'] = this.specialtyCode; + data['specialtyNameAr'] = this.specialtyNameAr; + data['specialtyNameEn'] = this.specialtyNameEn; + return data; + } +} diff --git a/lib/pages/login/confirm-login.dart b/lib/pages/login/confirm-login.dart index c53291f8..609d16bc 100644 --- a/lib/pages/login/confirm-login.dart +++ b/lib/pages/login/confirm-login.dart @@ -9,6 +9,7 @@ import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/card/rounded_container.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/otp/sms-popup.dart'; @@ -59,6 +60,8 @@ class _ConfirmLogin extends State { static bool _loading; + int fingrePrintBefore; + @override void initState() { _getAvailableBiometrics(); @@ -225,22 +228,22 @@ class _ConfirmLogin extends State { child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ - // Row( - // children: [ - // Expanded( - // child: RaisedButton( - // color: Colors.grey, - // textColor: Colors.white, - // child: - // Text(TranslationBase.of(context).registerNow), - // onPressed: () => { - // Navigator.of(context).pushNamed( - // REGISTER, - // ) - // }, - // )) - // ], - // ), + user != null + ? Row( + children: [ + Expanded( + child: DefaultButton( + TranslationBase.of(context) + .useAnotherAccount, + () => { + Navigator.of(context).pushNamed( + LOGIN_TYPE, + ) + }, + )), + ], + ) + : SizedBox(), ], )) ], @@ -263,8 +266,12 @@ class _ConfirmLogin extends State { } authenticateUser(type, isActive) { - this.selectedOption = - type; //this.selectedOption && !this.onlySMSBox ? this.selectedOption : this.fingrePrintBefore ? this.fingrePrintBefore : el.value; + if (type == 2 || type == 3) { + fingrePrintBefore = type; + } + this.selectedOption = user.logInType == 3 || user.logInType == 2 + ? user.logInType + : fingrePrintBefore != null ? fingrePrintBefore : type; switch (type) { case 1: @@ -283,7 +290,7 @@ class _ConfirmLogin extends State { break; } sharedPref.setInt(LAST_LOGIN, - type); //this.cs.sharedService.setStorage(this.selectedOption, AuthenticationService.LAST_LOGIN); + this.selectedOption); //this.cs.sharedService.setStorage(this.selectedOption, AuthenticationService.LAST_LOGIN); } loginWithSMS(type, isActive) { @@ -364,7 +371,7 @@ class _ConfirmLogin extends State { getMobileInfo(request) { this.authService.getLoginInfo(request).then((result) => { - if (!result['SMSLoginRequired']) + if (result['SMSLoginRequired'] == false) { this.loginTokenID = result.logInTokenID, this.patientOutSA = result.patientOutSA, @@ -379,10 +386,12 @@ class _ConfirmLogin extends State { } else { - if (result['IsAuthenticated']) + if (result['IsAuthenticated'] == true) { setState(() { + isMoreOption = true; this.onlySMSBox = true; + // this.fingrePrintBefore = true; }), //sharedPref.setBool(ONLY_SMS, true), @@ -471,7 +480,7 @@ class _ConfirmLogin extends State { this.authService.checkActivationCode(request, value: value).then((result) => { - if (result != null) + if (result is Map) { result = CheckActivationCode.fromJson(result), @@ -482,14 +491,16 @@ class _ConfirmLogin extends State { this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), this.sharedPref.setString(TOKEN, result.authenticationTokenID), this.checkIfUserAgreedBefore(result), - Navigator.of(context).pop(), + // Navigator.of(context).pop(), SMSOTP.showLoadingDialog(context, false), } else { - AppToast.showErrorToast(message: 'Please Enter Valid Code'), - Navigator.of(context).pop(), - SMSOTP.showLoadingDialog(context, false) + // Navigator.of(context).pop(), + SMSOTP.showLoadingDialog(context, false), + Future.delayed(Duration(seconds: 1), () { + AppToast.showErrorToast(message: result); + }), } }); } @@ -677,7 +688,7 @@ class _ConfirmLogin extends State { borderColor: Colors.grey, showBorder: true, child: Padding( - padding: EdgeInsets.fromLTRB(0, 10, 0, 5), + padding: EdgeInsets.fromLTRB(0, 0, 0, 5), child: Column( children: [ Image.asset( diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 5d43deb8..7f58551b 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -105,7 +105,7 @@ class _Login extends State { () => {this.startLogin()}, color: isButtonDisabled == true ? Colors.grey - : Colors.grey[600], + : Colors.grey[900], textColor: Colors.white, )) ], @@ -123,8 +123,8 @@ class _Login extends State { } void validateForm() { - if (validateIDBox(nationalIDorFile.text) == true && - mobileNo != null && + if (util.validateIDBox(nationalIDorFile.text, loginType) == true && + mobileNo.length >= 9 && util.isSAUDIIDValid(nationalIDorFile.text) == true) { setState(() { isButtonDisabled = false; @@ -136,18 +136,6 @@ class _Login extends State { } } - bool validateIDBox(String value) { - Pattern pattern = loginIDPattern(); //r'^\d+(?:\.\d+)?$'; - - RegExp regex = new RegExp(pattern); - return regex.hasMatch(value); - } - - String loginIDPattern() { - var length = loginType == 1 ? 10 : 7; - return "([0-9]{" + length.toString() + "})"; - } - checkUserAuthentication() { showLoader(true); var request = CheckPatientAuthenticationReq(); diff --git a/lib/pages/login/register-info.dart b/lib/pages/login/register-info.dart new file mode 100644 index 00000000..51caa972 --- /dev/null +++ b/lib/pages/login/register-info.dart @@ -0,0 +1,132 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:diplomaticquarterapp/models/Authentication/register_info_response.dart'; +import 'package:diplomaticquarterapp/pages/login/login-type.dart'; +import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; +import 'package:diplomaticquarterapp/widgets/card/rounded_container.dart'; +import 'package:diplomaticquarterapp/widgets/input/text_field.dart'; +import 'package:diplomaticquarterapp/widgets/mobile-no/mobile_no.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class RegisterInfo extends StatefulWidget { + @override + _RegisterInfo createState() => _RegisterInfo(); +} + +class _RegisterInfo extends State { + final authService = new AuthProvider(); + final sharedPref = new AppSharedPreferences(); + RegisterInfoResponse registerInfo; + bool isLoading; + + @override + void initState() { + getRegisterInfo(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return AppScaffold( + appBarTitle: TranslationBase.of(context).register, + isShowAppBar: true, + body: SingleChildScrollView( + child: Container( + padding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30), + height: SizeConfig.realScreenHeight * .9, + width: SizeConfig.realScreenWidth, + child: Column(children: [ + Expanded( + flex: 1, + child: AppText( + TranslationBase.of(context).patientInfo, + fontSize: SizeConfig.textMultiplier * 3, + textAlign: TextAlign.left, + )), + registerInfo != null + ? Expanded( + flex: 4, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Container( + child: TextFields( + hintText: registerInfo.idNumber, + prefixIcon: + Icon(Icons.chrome_reader_mode, color: Colors.red), + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + Container( + child: TextFields( + hintText: registerInfo.firstNameEn + + ' ' + + registerInfo.lastNameEn, + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + Container( + child: TextFields( + hintText: registerInfo.maritalStatusCode, + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + Container( + child: TextFields( + prefixIcon: + Icon(Icons.chrome_reader_mode, color: Colors.red), + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + hintText: TranslationBase.of(context).nationalID, + )), + Container( + child: TextFields( + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + hintText: TranslationBase.of(context).nationalID, + )), + ], + ), + ) + : SizedBox(), + Expanded( + flex: 2, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + children: [ + Expanded( + child: DefaultButton( + TranslationBase.of(context).registerNow, + () => {registerNow()}, + textColor: Colors.white, + )) + ], + ), + ], + )) + ]), + ))); + } + + registerNow() {} + getRegisterInfo() async { + registerInfo = + RegisterInfoResponse.fromJson(await sharedPref.getObject(NHIC_DATA)); + + print(await sharedPref.getObject(NHIC_DATA)); + } +} diff --git a/lib/pages/login/register.dart b/lib/pages/login/register.dart index 0d4244b0..e87f42c2 100644 --- a/lib/pages/login/register.dart +++ b/lib/pages/login/register.dart @@ -1,12 +1,22 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:diplomaticquarterapp/models/Authentication/check_user_status_reponse.dart'; +import 'package:diplomaticquarterapp/models/Authentication/check_user_status_req.dart'; +import 'package:diplomaticquarterapp/models/Authentication/checkpatient_for_registration.dart'; import 'package:diplomaticquarterapp/pages/login/login-type.dart'; +import 'package:diplomaticquarterapp/routes.dart'; +import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/card/rounded_container.dart'; import 'package:diplomaticquarterapp/widgets/input/text_field.dart'; import 'package:diplomaticquarterapp/widgets/mobile-no/mobile_no.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart'; import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -17,122 +27,253 @@ class Register extends StatefulWidget { } class _Register extends State { - final TextEditingController nationalIDorFile = null; + final nationalIDorFile = TextEditingController(); final int loginType = LoginType.loginType; - final TextEditingController mobileNo = null; + String mobileNo; + String countryCode = '966'; var isHijri; - + final util = Utils(); DateTime selectedDate; + String dob; + bool isButtonDisabled = true; + final authService = new AuthProvider(); + final sharedPref = new AppSharedPreferences(); + + bool isLoading; @override Widget build(BuildContext context) { return AppScaffold( appBarTitle: TranslationBase.of(context).register, isShowAppBar: true, - body: SingleChildScrollView( - child: Container( - padding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30), - height: SizeConfig.realScreenHeight * .9, - width: SizeConfig.realScreenWidth, - child: Column(children: [ - Expanded( - flex: 1, - child: AppText( - TranslationBase.of(context).enterNationalId, - fontSize: SizeConfig.textMultiplier * 3, - textAlign: TextAlign.left, - )), - Expanded( - flex: 4, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - MobileNo(controller: mobileNo), - Container( - child: TextFields( - controller: nationalIDorFile, - prefixIcon: - Icon(Icons.chrome_reader_mode, color: Colors.red), - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - hintText: TranslationBase.of(context).nationalID, - )), - Row( - children: [ - Expanded( - child: Row( + body: isLoading == true + ? AppCircularProgressIndicator() + : SingleChildScrollView( + child: Container( + padding: + EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30), + height: SizeConfig.realScreenHeight * .9, + width: SizeConfig.realScreenWidth, + child: Column(children: [ + Expanded( + flex: 1, + child: AppText( + TranslationBase.of(context).enterNationalId, + fontSize: SizeConfig.textMultiplier * 3, + textAlign: TextAlign.left, + )), + Expanded( + flex: 4, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + MobileNo( + onNumberChange: (value) => + {mobileNo = value, validateForm()}, + onCountryChange: (value) => countryCode = value), + Container( + child: TextFields( + controller: nationalIDorFile, + onChanged: (value) => validateForm(), + prefixIcon: + Icon(Icons.chrome_reader_mode, color: Colors.red), + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + hintText: TranslationBase.of(context).nationalID, + )), + Row( children: [ - Radio( - value: 1, - groupValue: isHijri, - onChanged: (value) { - setState(() { - isHijri = value; - }); - }, + Expanded( + child: Row( + children: [ + Radio( + value: 1, + groupValue: isHijri, + onChanged: (value) { + setState(() { + isHijri = value; + }); + validateForm(); + }, + ), + Text(TranslationBase.of(context).hijriDate), + ], + ), ), - Text(TranslationBase.of(context).hijriDate), - ], - ), - ), - Expanded( - child: Row( - children: [ - Radio( - value: 0, - groupValue: isHijri, - onChanged: (value) { - setState(() { - isHijri = value; - }); - }, + Expanded( + child: Row( + children: [ + Radio( + value: 0, + groupValue: isHijri, + onChanged: (value) { + setState(() { + isHijri = value; + }); + validateForm(); + }, + ), + Text(TranslationBase.of(context) + .gregorianDate), + ], + ), ), - Text(TranslationBase.of(context).gregorianDate), ], ), - ), - ], - ), - Row(children: [ - Expanded( - child: RaisedButton.icon( - onPressed: () => {_selectDate(context)}, - icon: Icon(Icons.date_range), - label: Text(selectedDate != null - ? "${selectedDate.toLocal()}".split(' ')[0] - : TranslationBase.of(context).dob))) - ]) - ], - ), - ), - Expanded( - flex: 2, - child: Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Row( - children: [ - Expanded( - child: DefaultButton( - TranslationBase.of(context).login, - () => {}, - )) + Row(children: [ + Expanded( + child: isHijri == 1 + ? TextFields( + onChanged: (value) => {dob = value}, + hintText: 'DD/MM/YYYY', + prefixIcon: Icon(Icons.date_range), + ) + : RaisedButton.icon( + onPressed: () => { + if (isHijri != null) + _selectDate(context) + }, + icon: Icon(Icons.date_range), + label: Text(selectedDate != null + ? "${selectedDate.toLocal()}" + .split(' ')[0] + : TranslationBase.of(context).dob))) + ]) ], ), - ], - )) - ]), - ))); + ), + Expanded( + flex: 2, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + children: [ + Expanded( + child: DefaultButton( + TranslationBase.of(context).registerNow, + () => {startRegistration()}, + textColor: Colors.white, + color: isButtonDisabled == true + ? Colors.grey + : Colors.grey[900])) + ], + ), + ], + )) + ]), + ))); } Future _selectDate(BuildContext context) async { final DateTime picked = await showDatePicker( context: context, initialDate: DateTime.now(), - firstDate: DateTime(2015, 8), - lastDate: DateTime(2101)); + firstDate: DateTime(1950, 8), + lastDate: DateTime.now()); if (picked != null && picked != selectedDate) setState(() { selectedDate = picked; }); } + + startRegistration() { + if (isButtonDisabled == false) { + var request = CheckPatientForRegistration(); + request.patientMobileNumber = int.parse(mobileNo); + request.zipCode = countryCode; + request.patientOutSA = countryCode == '966' ? 0 : 1; + // if (this.loginType == 1) { + request.patientIdentificationID = int.parse(nationalIDorFile.text); + request.patientID = 0; + // } else { + // request.patientIdentificationID = 0; + // request.patientID = int.parse(nationalIDorFile.text); + // } + this.checkPatientForRegisteration(request); + } + } + + checkPatientForRegisteration(request) { + showLoader(true); + this + .authService + .checkPatientForRegisteration(request) + .then((response) => {checkUserStatus(response, request)}); + } + + void validateForm() { + if (util.validateIDBox(nationalIDorFile.text, loginType) == true && + mobileNo.length >= 9 && + util.isSAUDIIDValid(nationalIDorFile.text) == true && + isHijri != null) { + setState(() { + isButtonDisabled = false; + }); + } else { + setState(() { + isButtonDisabled = true; + }); + } + } + + checkUserStatus(response, CheckPatientForRegistration request) async { + showLoader(false); + if (response is Map) { + var nRequest = request.toJson(); + nRequest['LogInTokenID'] = response['LogInTokenID']; + if (response['hasFile'] == true) { + AppToast.showErrorToast(message: response['ErrorEndUserMessage']); + //confirm box need to implement + // this.cs.confirmLogin(); + } else { + nRequest['forRegister'] = true; + sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest); + + this.chekUserData(response['LogInTokenID']); + } + } else { + if (response['ErrorCode'] == '-986') { + AppToast.showErrorToast(message: response['ErrorEndUserMessage']); + } + } + } + + chekUserData(loginToken) { + // let m = hijri(this.dateOfBirth).locale('en'); + // // const dateHijri = m.format('iDD/iMM/iYYYY'); + // const request = { + // PatientIdentificationID: this.id.toString(), + // // TokenID: token, + // DOB: this.dateOption === '1' ? this.dateOfBirth : moment(this.dateOfBirth).format('DD/MM/YYYY'), + // IsHijri: Number(this.dateOption) + // } + showLoader(true); + var request = CheckUserStatusRequest(); + request.patientIdentificationID = nationalIDorFile.text; + request.dOB = isHijri == 1 + ? dob + : "${selectedDate.toLocal()}".split(' ')[0].replaceAll('-', '/'); + request.isHijri = isHijri; + request.patientOutSA = countryCode == '966' ? 0 : 1; + this.authService.checkUserStatus(request).then((result) => { + showLoader(false), + if (result is Map) + { + result = CheckUserStatusResponse.fromJson(result), + sharedPref.setObject(NHIC_DATA, result), + Navigator.of(context).pushNamed( + REGISTER_INFO, + ) + } + else + {AppToast.showErrorToast(message: result['ErrorEndUserMessage'])} + //this.onRegister(); + }); + } + + showLoader(bool isTrue) { + setState(() { + isLoading = isTrue; + }); + } } diff --git a/lib/routes.dart b/lib/routes.dart index 91126829..2c68ed21 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/pages/login/confirm-login.dart'; import 'package:diplomaticquarterapp/pages/login/forgot-password.dart'; +import 'package:diplomaticquarterapp/pages/login/register-info.dart'; import 'package:diplomaticquarterapp/pages/login/welcome.dart'; import 'package:diplomaticquarterapp/pages/login/login-type.dart'; import 'package:diplomaticquarterapp/pages/login/login.dart'; @@ -17,6 +18,7 @@ const String LOGIN_PAGE = 'login-page'; const String FORGOT_PASSWORD = 'forgot-password'; const String REGISTER = 'register'; const String CONFIRM_LOGIN = 'confrim-login'; +const String REGISTER_INFO = 'register-info'; var routes = { // ROOT: (_) => RootPage(), HOME: (_) => LandingPage(), @@ -25,5 +27,6 @@ var routes = { LOGIN_PAGE: (_) => Login(), FORGOT_PASSWORD: (_) => ForgotPassword(), REGISTER: (_) => Register(), - CONFIRM_LOGIN: (_) => ConfirmLogin() + CONFIRM_LOGIN: (_) => ConfirmLogin(), + REGISTER_INFO: (_) => RegisterInfo() }; diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index 6bb7284b..4b0717b4 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -6,6 +6,8 @@ import 'package:diplomaticquarterapp/models/Authentication/check_activation_code import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart'; +import 'package:diplomaticquarterapp/models/Authentication/check_user_status_req.dart'; +import 'package:diplomaticquarterapp/models/Authentication/checkpatient_for_registration.dart'; import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_request.dart'; import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_response.dart'; import 'package:diplomaticquarterapp/models/Authentication/insert_device_imei_request.dart'; @@ -29,6 +31,10 @@ const GET_MOBILE_INFO = '/Authentication.svc/REST/GetMobileLoginInfo'; const SEND_ACTIVATION_CODE = '/Authentication.svc/REST/SendActivationCodebyOTPNotificationType'; const CHECK_ACTIVATION_CODE = '/Authentication.svc/REST/CheckActivationCode'; +const CHECK_PATIENT_FOR_REGISTRATION = + "/Authentication.svc/REST/CheckPatientForRegisteration"; + +const CHECK_USER_STATUS = "/NHIC.svc/REST/GetPatientInfo"; class AuthProvider with ChangeNotifier { bool isLogin = false; @@ -147,7 +153,7 @@ class AuthProvider with ChangeNotifier { request.channel = CHANNEL; request.iPAdress = IP_ADDRESS; request.generalid = GENERAL_ID; - request.languageID = 2; + request.languageID = LANGUAGE_ID; request.patientOutSA = request.zipCode == '966' ? 0 : 1; try { dynamic localRes; @@ -169,7 +175,7 @@ class AuthProvider with ChangeNotifier { request.channel = CHANNEL; request.iPAdress = IP_ADDRESS; request.generalid = GENERAL_ID; - request.languageID = 2; + request.languageID = LANGUAGE_ID; request.deviceTypeID = DeviceTypeID; request.patientOutSA = request.zipCode == '966' ? 0 : 1; request.isDentalAllowedBackend = false; @@ -193,7 +199,7 @@ class AuthProvider with ChangeNotifier { request.channel = CHANNEL; request.iPAdress = IP_ADDRESS; request.generalid = GENERAL_ID; - request.languageID = 2; + request.languageID = LANGUAGE_ID; request.deviceTypeID = DeviceTypeID; request.patientOutSA = request.zipCode == '966' ? 0 : 1; request.isDentalAllowedBackend = false; @@ -202,7 +208,7 @@ class AuthProvider with ChangeNotifier { await new BaseAppClient().post(SEND_ACTIVATION_CODE, onSuccess: (dynamic response, int statusCode) { localRes = response; - authenticatedUser = localRes; + authenticatedUser = CheckActivationCode.fromJson(localRes); }, onFailure: (String error, int statusCode) { throw error; }, body: request.toJson()); @@ -213,7 +219,7 @@ class AuthProvider with ChangeNotifier { } } - Future checkActivationCode(request, {value}) async { + Future checkActivationCode(request, {value}) async { var neRequest = CheckActivationCodeReq.fromJson(request); neRequest.activationCode = value ?? "0000"; neRequest.isSilentLogin = value != null ? false : true; @@ -222,24 +228,25 @@ class AuthProvider with ChangeNotifier { neRequest.channel = CHANNEL; neRequest.iPAdress = IP_ADDRESS; neRequest.generalid = GENERAL_ID; - neRequest.languageID = 2; + neRequest.languageID = LANGUAGE_ID; neRequest.deviceTypeID = DeviceTypeID; neRequest.patientOutSA = neRequest.zipCode == '966' ? 0 : 1; neRequest.projectOutSA = neRequest.zipCode == '966' ? 0 : 1; neRequest.isDentalAllowedBackend = false; + dynamic localRes; try { - dynamic localRes; await new BaseAppClient().post(CHECK_ACTIVATION_CODE, onSuccess: (dynamic response, int statusCode) { localRes = response; //CheckActivationCode.fromJson(); }, onFailure: (String error, int statusCode) { - throw error; + localRes = error; + return Future.value(error); + // throw error; }, body: neRequest.toJson()); return Future.value(localRes); } catch (error) { - Future.error(error); - throw error; + //return Future.value(error); } } @@ -247,4 +254,53 @@ class AuthProvider with ChangeNotifier { this.isLogin = true; return authenticatedUser; } + + Future checkPatientForRegisteration( + CheckPatientForRegistration request) async { + request.versionID = VERSION_ID; + request.channel = CHANNEL; + request.iPAdress = IP_ADDRESS; + request.generalid = GENERAL_ID; + request.deviceTypeID = DeviceTypeID; + request.languageID = LANGUAGE_ID; + request.isRegister = false; + // request.tokenID = ''; + dynamic localRes; + try { + await new BaseAppClient().post(CHECK_PATIENT_FOR_REGISTRATION, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + localRes = error; + return Future.value(error); + }, body: request.toJson()); + return Future.value(localRes); + } catch (error) { + throw error; + } + } + + Future checkUserStatus(CheckUserStatusRequest request) async { + request.versionID = VERSION_ID; + request.channel = CHANNEL; + request.iPAdress = IP_ADDRESS; + request.generalid = GENERAL_ID; + request.deviceTypeID = DeviceTypeID; + request.languageID = LANGUAGE_ID; + + // request.tokenID = ''; + dynamic localRes; + try { + await new BaseAppClient().post(CHECK_USER_STATUS, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + localRes = error; + return Future.value(error); + }, body: request.toJson()); + return Future.value(localRes); + } catch (error) { + throw error; + } + } } diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 1e728ed3..1ac7b12f 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -174,6 +174,8 @@ class TranslationBase { localizedValues['welcome-back'][locale.languageCode]; String get accountInfo => localizedValues['account-info'][locale.languageCode]; + String get useAnotherAccount => + localizedValues['another-acc'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate { diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index ac586b7d..455279cc 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -80,4 +80,16 @@ class Utils { } catch (err) {} return false; } + + bool validateIDBox(String value, type) { + Pattern pattern = loginIDPattern(type); //r'^\d+(?:\.\d+)?$'; + + RegExp regex = new RegExp(pattern); + return regex.hasMatch(value); + } + + String loginIDPattern(loginType) { + var length = loginType == 1 ? 10 : 7; + return "([0-9]{" + length.toString() + "})"; + } } diff --git a/lib/widgets/otp/sms-popup.dart b/lib/widgets/otp/sms-popup.dart index da244324..709a8f0e 100644 --- a/lib/widgets/otp/sms-popup.dart +++ b/lib/widgets/otp/sms-popup.dart @@ -284,11 +284,12 @@ class SMSOTP { static void showLoadingDialog(BuildContext context, bool _loading) async { _context = context; - _loading = true; + if (_loading == false) { Navigator.of(context).pop(); return; } + _loading = true; await showDialog( context: _context, barrierDismissible: false, From ecfa1756d3cce5ee8eedaba059703d415263e20a Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Sun, 9 Aug 2020 09:55:43 +0300 Subject: [PATCH 4/4] login changes --- lib/config/localized_values.dart | 1 + lib/pages/login/login.dart | 2 +- lib/pages/login/register-info.dart | 124 +++++++++++++---------- lib/pages/login/register.dart | 2 +- lib/uitl/translations_delegate_base.dart | 1 + lib/uitl/utils.dart | 66 ++++++------ 6 files changed, 112 insertions(+), 84 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 112b3561..c600610b 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -138,4 +138,5 @@ const Map> localizedValues = { "ar": "هل ترغب في تسجيل الدخول باسم المستخدم الحالي؟" }, "another-acc": {"en": "Use Another Account", "ar": "استخدم حسابا آخر"}, + "next": {"en": "Next", "ar": 'التالى'}, }; diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 7f58551b..1b482299 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -125,7 +125,7 @@ class _Login extends State { void validateForm() { if (util.validateIDBox(nationalIDorFile.text, loginType) == true && mobileNo.length >= 9 && - util.isSAUDIIDValid(nationalIDorFile.text) == true) { + util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true) { setState(() { isButtonDisabled = false; }); diff --git a/lib/pages/login/register-info.dart b/lib/pages/login/register-info.dart index 51caa972..70e5fb29 100644 --- a/lib/pages/login/register-info.dart +++ b/lib/pages/login/register-info.dart @@ -27,7 +27,7 @@ class _RegisterInfo extends State { final sharedPref = new AppSharedPreferences(); RegisterInfoResponse registerInfo; bool isLoading; - + int page = 1; @override void initState() { getRegisterInfo(); @@ -52,55 +52,71 @@ class _RegisterInfo extends State { fontSize: SizeConfig.textMultiplier * 3, textAlign: TextAlign.left, )), - registerInfo != null - ? Expanded( - flex: 4, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Container( - child: TextFields( - hintText: registerInfo.idNumber, - prefixIcon: - Icon(Icons.chrome_reader_mode, color: Colors.red), - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - Container( - child: TextFields( - hintText: registerInfo.firstNameEn + - ' ' + - registerInfo.lastNameEn, - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - Container( - child: TextFields( - hintText: registerInfo.maritalStatusCode, - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - Container( - child: TextFields( - prefixIcon: - Icon(Icons.chrome_reader_mode, color: Colors.red), - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - hintText: TranslationBase.of(context).nationalID, - )), - Container( - child: TextFields( - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - hintText: TranslationBase.of(context).nationalID, - )), - ], - ), + registerInfo != null && page == 1 + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + AppText('National ID'), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.idNumber, + prefixIcon: Icon(Icons.chrome_reader_mode, + color: Colors.red), + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + AppText('Name'), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.firstNameEn + + ' ' + + registerInfo.lastNameEn, + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + AppText('Gender'), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.maritalStatusCode == 'U' + ? 'Unknown' + : registerInfo.maritalStatusCode == 'M' + ? 'Male' + : 'Female', + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + AppText('Nationality'), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.nationalityCode, + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + AppText('Date of Birth'), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.dateOfBirth, + padding: EdgeInsets.only( + top: 20, bottom: 20, left: 10, right: 10), + readOnly: true, + )), + ], ) - : SizedBox(), + : registerInfo != null && page == 2 + ? Column( + children: [], + ) + : SizedBox(), Expanded( flex: 2, child: Column( @@ -110,8 +126,8 @@ class _RegisterInfo extends State { children: [ Expanded( child: DefaultButton( - TranslationBase.of(context).registerNow, - () => {registerNow()}, + TranslationBase.of(context).next, + () => {nextPage()}, textColor: Colors.white, )) ], @@ -122,6 +138,12 @@ class _RegisterInfo extends State { ))); } + nextPage() { + setState(() { + page++; + }); + } + registerNow() {} getRegisterInfo() async { registerInfo = diff --git a/lib/pages/login/register.dart b/lib/pages/login/register.dart index e87f42c2..5197b652 100644 --- a/lib/pages/login/register.dart +++ b/lib/pages/login/register.dart @@ -204,7 +204,7 @@ class _Register extends State { void validateForm() { if (util.validateIDBox(nationalIDorFile.text, loginType) == true && mobileNo.length >= 9 && - util.isSAUDIIDValid(nationalIDorFile.text) == true && + util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true && isHijri != null) { setState(() { isButtonDisabled = false; diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 1ac7b12f..2cf6ca23 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -176,6 +176,7 @@ class TranslationBase { localizedValues['account-info'][locale.languageCode]; String get useAnotherAccount => localizedValues['another-acc'][locale.languageCode]; + String get next => localizedValues['next'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate { diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index 455279cc..7a987279 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -43,42 +43,46 @@ class Utils { FocusScope.of(context).unfocus(); } - bool isSAUDIIDValid(String id) { - if (id == null) { - return false; - } - try { - id = id.toString(); - id = id.trim(); - var returnValue = int.parse(id); - var sum = 0; - if (returnValue > 0) { - var type = int.parse(id[0]); + bool isSAUDIIDValid(String id, type) { + if (type == 1) { + if (id == null) { + return false; + } + try { + id = id.toString(); + id = id.trim(); + var returnValue = int.parse(id); + var sum = 0; + if (returnValue > 0) { + var type = int.parse(id[0]); - if (id.length != 10) { - return false; - } - if (type != 2 && type != 1) { - return false; - } + if (id.length != 10) { + return false; + } + if (type != 2 && type != 1) { + return false; + } - for (var i = 0; i < 10; i++) { - if (i % 2 == 0) { - var a = id[i]; - var x = int.parse(a) * 2; - var b = x.toString(); - if (b.length == 1) { - b = "0" + b; + for (var i = 0; i < 10; i++) { + if (i % 2 == 0) { + var a = id[i]; + var x = int.parse(a) * 2; + var b = x.toString(); + if (b.length == 1) { + b = "0" + b; + } + sum += int.parse(b[0]) + int.parse(b[1]); + } else { + sum += int.parse(id[i]); } - sum += int.parse(b[0]) + int.parse(b[1]); - } else { - sum += int.parse(id[i]); } + return sum % 10 == 0; } - return sum % 10 == 0; - } - } catch (err) {} - return false; + } catch (err) {} + return false; + } else { + return true; + } } bool validateIDBox(String value, type) {