diff --git a/assets/langs/ar-SA.json b/assets/langs/ar-SA.json index b4f7eb6..bf408fc 100644 --- a/assets/langs/ar-SA.json +++ b/assets/langs/ar-SA.json @@ -11,6 +11,7 @@ "lastLoginDetails": "تفاصيل تسجيل الدخول الأخير:", "verificationType": "نوع التحقق:", "pleaseVerify": "ارجوك تحقق", + "pleaseVerifyForBio": "الرجاء التحقق من تسجيل الدخول باستخدام أحد هذه الخيارات", "verifyThroughFace": "تحقق من خلال الوجه", "verifyThroughFingerprint": "تحقق من خلال بصمة الإصبع", "verifyThroughSMS": "تحقق من خلال الرسائل القصيرة", diff --git a/assets/langs/en-US.json b/assets/langs/en-US.json index 7e0d3f7..d128c31 100644 --- a/assets/langs/en-US.json +++ b/assets/langs/en-US.json @@ -11,6 +11,7 @@ "lastLoginDetails": "Last Login Details:", "verificationType": "Verification Type:", "pleaseVerify": "Please Verify", + "pleaseVerifyForBio": "Please verify login with one of the following options", "verifyThroughFace": "Verify Through Face", "verifyThroughFingerprint": "Verify Through Fingerprint", "verifyThroughSMS": "Verify Through SMS", diff --git a/lib/api/login_api_client.dart b/lib/api/login_api_client.dart index 79b7783..3cdda6d 100644 --- a/lib/api/login_api_client.dart +++ b/lib/api/login_api_client.dart @@ -23,7 +23,7 @@ class LoginApiClient { postParams["DeviceType"] = deviceType; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); - return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? responseData.mohemmGetMobileLoginInfoList!.first : null; + return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? (responseData.mohemmGetMobileLoginInfoList!.first) : null; }, url, postParams); } diff --git a/lib/dialogs/otp_dialog.dart b/lib/dialogs/otp_dialog.dart index b761f00..bea34f3 100644 --- a/lib/dialogs/otp_dialog.dart +++ b/lib/dialogs/otp_dialog.dart @@ -87,7 +87,7 @@ class OtpDialog { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SvgPicture.asset( - type == 1 ? "assets/images/login/verify_sms.svg" : "assets/images/login/verify_whatsapp.svg", + type == 1 ? "assets/images/login/verify_sms.svg" :type==2? "assets/images/login/verify_thumb.svg":type==3? "assets/images/login/verify_face.svg":'assets/images/login/verify_whatsapp.svg', height: 50, width: 50, ), diff --git a/lib/generated/locale_keys.g.dart b/lib/generated/locale_keys.g.dart index 16ceab4..031378d 100644 --- a/lib/generated/locale_keys.g.dart +++ b/lib/generated/locale_keys.g.dart @@ -13,6 +13,7 @@ abstract class LocaleKeys { static const lastLoginDetails = 'lastLoginDetails'; static const verificationType = 'verificationType'; static const pleaseVerify = 'pleaseVerify'; + static const pleaseVerifyForBio = 'pleaseVerifyForBio'; static const verifyThroughFace = 'verifyThroughFace'; static const verifyThroughFingerprint = 'verifyThroughFingerprint'; static const verifyThroughSMS = 'verifyThroughSMS'; diff --git a/lib/ui/login/verify_last_login_screen.dart b/lib/ui/login/verify_last_login_screen.dart index f47b2a4..faaf76e 100644 --- a/lib/ui/login/verify_last_login_screen.dart +++ b/lib/ui/login/verify_last_login_screen.dart @@ -22,6 +22,11 @@ import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/models/get_mobile_login_info_list_model.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart'; +// WhatsApp 4 +// SMS 1 +// Face ID 3 +// Finger Print 2 + class VerifyLastLoginScreen extends StatefulWidget { VerifyLastLoginScreen({Key? key}) : super(key: key); @@ -36,6 +41,10 @@ class _VerifyLastLoginScreenState extends State { List _availableBioMetricType = []; GetMobileLoginInfoListModel? mobileLoginInfoListModel; + //For face and finger print verification + int selectedFlag = 0; + bool isNeedVerifyWithFaceIDAndBiometrics = false; + @override void initState() { _getAvailableBiometrics(); @@ -47,6 +56,7 @@ class _VerifyLastLoginScreenState extends State { Widget build(BuildContext context) { mobileLoginInfoListModel ??= ModalRoute.of(context)!.settings.arguments as GetMobileLoginInfoListModel; String empName = AppState().isArabic(context) ? AppState().memberInformationList!.eMPLOYEEDISPLAYNAMEAr! : AppState().memberInformationList!.eMPLOYEEDISPLAYNAMEEn!; + print("selectedFlag1: " + mobileLoginInfoListModel!.loginType.toString()); return Scaffold( appBar: AppBar( backgroundColor: Colors.transparent, @@ -110,15 +120,16 @@ class _VerifyLastLoginScreenState extends State { ), ), LocaleKeys.pleaseVerify.tr().toText16(), + if (isNeedVerifyWithFaceIDAndBiometrics) LocaleKeys.pleaseVerifyForBio.tr().toText12(), GridView( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9), physics: const NeverScrollableScrollPhysics(), padding: const EdgeInsets.only(top: 9), shrinkWrap: true, children: [ - getButton(3), + if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(3), + if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(2), getButton(4), - getButton(2), getButton(1), ], ) @@ -164,7 +175,7 @@ class _VerifyLastLoginScreenState extends State { DefaultButton( LocaleKeys.useAnotherAccount.tr(), () { - Navigator.pushNamedAndRemoveUntil(context, AppRoutes.login, (Route route) => false,arguments: false); + Navigator.pushNamedAndRemoveUntil(context, AppRoutes.login, (Route route) => false, arguments: false); }, ).insideContainer, ], @@ -221,62 +232,32 @@ class _VerifyLastLoginScreenState extends State { // isMoreOption = true; }); } else { - try { - Utils.showLoading(context); - if (_flag == 4 || _flag == 3) { - bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics(); - if (authenticateWithFaceAndTouchID) { - Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route route) => false); - return; + if (_flag == 2 || _flag == 3) { + bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics(); + if (!authenticateWithFaceAndTouchID) { + return; + } else { + if (mobileLoginInfoListModel!.loginType == 2 || mobileLoginInfoListModel!.loginType == 3) { + bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics(); + if (!authenticateWithFaceAndTouchID) { + return; + } else { + performApiCall(_title, _icon, _flag, isDirectLogin: true); + } } else { - Utils.hideLoading(context); - return; + isNeedVerifyWithFaceIDAndBiometrics = true; + selectedFlag = _flag; + setState(() { + return; + }); } } - await LoginApiClient().checkMobileAppVersion(); - await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!); - BasicMemberInformationModel? memberInformationModel = await LoginApiClient().mohemmSendActivationCodeByOTPNotificationType( - checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName); - Utils.hideLoading(context); - OtpDialog( - context, - _flag, - int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""), - (value) async { - Utils.showLoading(context); - try { - GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(false, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName); - GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW( - AppState().memberLoginList?.pEMAILADDRESS ?? "", - genericResponseModel?.pSESSIONID ?? 0, - genericResponseModel?.memberInformationList![0].eMPLOYEENAME ?? "", - _flag, - AppState().memberLoginList?.pMOBILENUMBER ?? "", - AppState().getUserName!, - mobileLoginInfoListModel!.deviceToken!, - Platform.isAndroid ? "android" : "ios"); - if (genericResponseModel?.errorMessage != null) { - Utils.showToast(genericResponseModel?.errorMessage ?? ""); - // Navigator.pop(context); - } - Utils.hideLoading(context); - Navigator.pop(context); - Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route route) => false); - } catch (ex) { - Utils.hideLoading(context); - Utils.handleException(ex, context, null); - } - }, - () => { - Navigator.pop(context), - }, - ).displayDialog(context); - } catch (ex) { - Utils.hideLoading(context); - Utils.handleException(ex, context, null); + } else { + if (isNeedVerifyWithFaceIDAndBiometrics) + performApiCall(_title, _icon, selectedFlag); + else + performApiCall(_title, _icon, _flag); } - - // authenticateUser(_flag, isActive: _loginIndex); } }, child: Container( @@ -305,14 +286,14 @@ class _VerifyLastLoginScreenState extends State { Widget getButton(int flag) { switch (flag) { - case 2: - return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null); case 1: return _loginOptionButton(LocaleKeys.verifyThroughSMS.tr(), 'assets/images/login/verify_sms.svg', flag, null); - case 4: + case 2: return _loginOptionButton(LocaleKeys.verifyThroughFingerprint.tr(), 'assets/images/login/verify_thumb.svg', flag, BiometricType.fingerprint.index); case 3: return _loginOptionButton(LocaleKeys.verifyThroughFace.tr(), 'assets/images/login/verify_face.svg', flag, BiometricType.face.index); + case 4: + return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null); default: return const SizedBox(); } @@ -328,6 +309,66 @@ class _VerifyLastLoginScreenState extends State { } return isAvailable; } + + Future performApiCall(String _title, String _icon, int _flag, {bool isDirectLogin = false}) async { + try { + if (isDirectLogin) + setState(() { + Utils.showLoading(context); + }); + else + Utils.showLoading(context); + await LoginApiClient().checkMobileAppVersion(); + await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!); + if (!isDirectLogin) + BasicMemberInformationModel? memberInformationModel = await LoginApiClient() + .mohemmSendActivationCodeByOTPNotificationType(checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName); + if (isDirectLogin) performDirectApiCall(_title, _icon, _flag, ""); + if (!isDirectLogin) Utils.hideLoading(context); + if (!isDirectLogin) + OtpDialog( + context, + _flag, + int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""), + (value) async { + Utils.showLoading(context); + performDirectApiCall(_title, _icon, _flag, value); + }, + () => { + Navigator.pop(context), + }, + ).displayDialog(context); + } catch (ex) { + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + Future performDirectApiCall(String _title, String _icon, int _flag, String value, {bool isDirectLogin = false}) async { + try { + GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(false, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName); + GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW( + AppState().memberLoginList?.pEMAILADDRESS ?? "", + genericResponseModel?.pSESSIONID ?? 0, + genericResponseModel?.memberInformationList![0].eMPLOYEENAME ?? "", + _flag, + AppState().memberLoginList?.pMOBILENUMBER ?? "", + AppState().getUserName!, + mobileLoginInfoListModel!.deviceToken!, + Platform.isAndroid ? "android" : "ios"); + if (genericResponseModel?.errorMessage != null) { + Utils.showToast(genericResponseModel?.errorMessage ?? ""); + // Navigator.pop(context); + } + Utils.hideLoading(context); + Navigator.pop(context); + Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route route) => false); + } catch (ex) { + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + // // formatDate(date) { // return date; diff --git a/lib/ui/login/verify_login_screen.dart b/lib/ui/login/verify_login_screen.dart index d03fb71..1d66df9 100644 --- a/lib/ui/login/verify_login_screen.dart +++ b/lib/ui/login/verify_login_screen.dart @@ -13,6 +13,7 @@ import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/dialogs/otp_dialog.dart'; +import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/models/basic_member_information_model.dart'; @@ -20,6 +21,11 @@ import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/models/member_information_list_model.dart'; import 'package:mohem_flutter_app/models/privilege_list_model.dart'; +// WhatsApp 4 +// SMS 1 +// Face ID 3 +// Finger Print 2 + class VerifyLoginScreen extends StatefulWidget { VerifyLoginScreen({Key? key}) : super(key: key); @@ -35,6 +41,10 @@ class _VerifyLoginScreenState extends State { String? firebaseToken; + //For face and finger print verification + int selectedFlag = 0; + bool isNeedVerifyWithFaceIDAndBiometrics = false; + @override void initState() { _getAvailableBiometrics(); @@ -59,15 +69,16 @@ class _VerifyLoginScreenState extends State { physics: const BouncingScrollPhysics(), children: [ LocaleKeys.pleaseVerify.tr().toText16(), + if (isNeedVerifyWithFaceIDAndBiometrics) LocaleKeys.pleaseVerifyForBio.tr().toText12(), GridView( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9), physics: const NeverScrollableScrollPhysics(), padding: const EdgeInsets.only(top: 9), shrinkWrap: true, children: [ - getButton(3), + if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(3), + if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(2), getButton(4), - getButton(2), getButton(1), ], ) @@ -500,6 +511,7 @@ class _VerifyLoginScreenState extends State { // } // + Future loginWithFaceIDAndBiometrics() async { IOSAuthMessages iosStrings = const IOSAuthMessages(cancelButton: 'cancel', goToSettingsButton: 'settings', goToSettingsDescription: 'Please set up your Touch ID.', lockOut: 'Please reenable your Touch ID'); @@ -525,69 +537,22 @@ class _VerifyLoginScreenState extends State { // isMoreOption = true; }); } else { - try { - Utils.showLoading(context); - if (_flag == 4 || _flag == 3) { - bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics(); - if (!authenticateWithFaceAndTouchID) { + if (_flag == 2 || _flag == 3) { + bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics(); + if (!authenticateWithFaceAndTouchID) { + return; + } else { + isNeedVerifyWithFaceIDAndBiometrics = true; + selectedFlag = _flag; + setState(() { return; - } + }); } - await LoginApiClient().checkMobileAppVersion(); - await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!); - BasicMemberInformationModel? memberInformationModel = await LoginApiClient().mohemmSendActivationCodeByOTPNotificationType( - checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName); - Utils.hideLoading(context); - OtpDialog( - context, - _flag, - int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""), - (value) async { - Utils.showLoading(context); - try { - GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(true, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName); - GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW( - AppState().memberLoginList?.pEMAILADDRESS ?? "", - genericResponseModel?.pSESSIONID ?? 0, - genericResponseModel?.memberInformationList![0].eMPLOYEENAME ?? "", - _flag, - AppState().memberLoginList?.pMOBILENUMBER ?? "", - AppState().getUserName!, - firebaseToken!, - Platform.isAndroid ? "android" : "ios"); - if (genericResponseModel?.errorMessage != null) { - Utils.showToast(genericResponseModel?.errorMessage ?? ""); - } else { - AppState().setPrivilegeListModel = genericResponseModel!.privilegeList ?? []; - AppState().setMemberInformationListModel = genericResponseModel.memberInformationList?.first; - MemberInformationListModel.saveToPrefs(genericResponseModel.memberInformationList ?? []); - genericResponseModel.privilegeList!.forEach((element) { - print(element.serviceName.toString() + " " + element.previlege.toString()); // Check availability - }); - PrivilegeListModel.saveToPrefs(genericResponseModel.privilegeList ?? []); - AppState().setMohemmWifiSSID = genericResponseModel.mohemmWifiSSID; - AppState().setMohemmWifiPassword = genericResponseModel.mohemmWifiPassword; - Utils.saveStringFromPrefs(SharedPrefsConsts.username, AppState().getUserName!); - Utils.saveStringFromPrefs(SharedPrefsConsts.password, AppState().password!); - Utils.saveStringFromPrefs(SharedPrefsConsts.mohemmWifiSSID, genericResponseModel.mohemmWifiSSID!); - Utils.saveStringFromPrefs(SharedPrefsConsts.mohemmWifiPassword, genericResponseModel.mohemmWifiPassword!); - } - Utils.hideLoading(context); - Navigator.pop(context); - Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route route) => false); - } catch (ex) { - print(ex); - Utils.hideLoading(context); - Utils.handleException(ex, context, null); - } - }, - () => { - Navigator.pop(context), - }, - ).displayDialog(context); - } catch (ex) { - Utils.hideLoading(context); - Utils.handleException(ex, context, null); + } else { + if (isNeedVerifyWithFaceIDAndBiometrics) + performApiCall(_title, _icon, selectedFlag); + else + performApiCall(_title, _icon, _flag); } } }, @@ -617,14 +582,14 @@ class _VerifyLoginScreenState extends State { Widget getButton(int flag) { switch (flag) { - case 2: - return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null); case 1: return _loginOptionButton(LocaleKeys.verifyThroughSMS.tr(), 'assets/images/login/verify_sms.svg', flag, null); - case 4: + case 2: return _loginOptionButton(LocaleKeys.verifyThroughFingerprint.tr(), 'assets/images/login/verify_thumb.svg', flag, BiometricType.fingerprint.index); case 3: return _loginOptionButton(LocaleKeys.verifyThroughFace.tr(), 'assets/images/login/verify_face.svg', flag, BiometricType.face.index); + case 4: + return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null); default: return const SizedBox(); } @@ -640,6 +605,67 @@ class _VerifyLoginScreenState extends State { } return isAvailable; } + + Future performApiCall(String _title, String _icon, int _flag) async { + try { + Utils.showLoading(context); + await LoginApiClient().checkMobileAppVersion(); + await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!); + BasicMemberInformationModel? memberInformationModel = await LoginApiClient() + .mohemmSendActivationCodeByOTPNotificationType(checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName); + Utils.hideLoading(context); + OtpDialog( + context, + _flag, + int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""), + (value) async { + Utils.showLoading(context); + try { + GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(true, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName); + GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW( + AppState().memberLoginList?.pEMAILADDRESS ?? "", + genericResponseModel?.pSESSIONID ?? 0, + genericResponseModel?.memberInformationList![0].eMPLOYEENAME ?? "", + _flag, + AppState().memberLoginList?.pMOBILENUMBER ?? "", + AppState().getUserName!, + firebaseToken!, + Platform.isAndroid ? "android" : "ios"); + if (genericResponseModel?.errorMessage != null) { + Utils.showToast(genericResponseModel?.errorMessage ?? ""); + } else { + AppState().setPrivilegeListModel = genericResponseModel!.privilegeList ?? []; + AppState().setMemberInformationListModel = genericResponseModel.memberInformationList?.first; + MemberInformationListModel.saveToPrefs(genericResponseModel.memberInformationList ?? []); + genericResponseModel.privilegeList!.forEach((element) { + print(element.serviceName.toString() + " " + element.previlege.toString()); // Check availability + }); + PrivilegeListModel.saveToPrefs(genericResponseModel.privilegeList ?? []); + AppState().setMohemmWifiSSID = genericResponseModel.mohemmWifiSSID; + AppState().setMohemmWifiPassword = genericResponseModel.mohemmWifiPassword; + Utils.saveStringFromPrefs(SharedPrefsConsts.username, AppState().getUserName!); + Utils.saveStringFromPrefs(SharedPrefsConsts.password, AppState().password!); + Utils.saveStringFromPrefs(SharedPrefsConsts.mohemmWifiSSID, genericResponseModel.mohemmWifiSSID!); + Utils.saveStringFromPrefs(SharedPrefsConsts.mohemmWifiPassword, genericResponseModel.mohemmWifiPassword!); + } + Utils.hideLoading(context); + Navigator.pop(context); + Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route route) => false); + } catch (ex) { + print(ex); + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + }, + () => { + Navigator.pop(context), + }, + ).displayDialog(context); + } catch (ex) { + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } // // formatDate(date) { // return date;