diff --git a/assets/images/login/more_icon.png b/assets/images/login/more_icon.png new file mode 100644 index 00000000..b696d345 Binary files /dev/null and b/assets/images/login/more_icon.png differ diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 822c945a..606d0b8c 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -120,5 +120,14 @@ const Map> 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' +