From 7d440b40249bd12b2c6906165eb6b56b5abab9ff Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Sun, 13 Jul 2025 09:53:57 +0300 Subject: [PATCH] savedlogin --- lib/config/localized_values.dart | 11 +- lib/pages/login/saved_login.dart | 251 +++++++++++++++++++++-- lib/uitl/translations_delegate_base.dart | 7 +- lib/widgets/quick_login.dart | 18 +- 4 files changed, 263 insertions(+), 24 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 8a9e5a4f..d2c6fa86 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -2333,5 +2333,14 @@ const Map localizedValues = { "loginBy": {"en": "Login By", "ar":"تسجيل الدخول بواسطة"}, "prepareToElevate": {"en": "Prepared to elevate your health and well-being?", "ar": "هل أنت مستعد لتحسين صحتك ورفاهتك؟"}, "alreadyHaveAccount": {"en": "Already have an account?", "ar": "هل لديك حساب بالفعل؟"}, - "loginNow": {"en": "Login Now", "ar": "تسجيل الدخول الآن"} + "loginNow": {"en": "Login Now", "ar": "تسجيل الدخول الآن"}, + "guest": {"en": "Guest", "ar":"ضيف"}, + "switchAccount": {"en": "Switch Account", "ar":"تبديل الحساب"}, + "allSet": {"en": "All Set! Now you can login with Face ID or Biometric", "ar":"جاهز! الآن يمكنك تسجيل الدخول باستخدام Face ID أو البصمة"}, + "enableQuickLogin": {"en": "Enable Quick Login", "ar":"تمكين تسجيل الدخول السريع"}, + "enableMsg": {"en": "Enabling the quick login will verify through your existing device Face ID / Biometric", "ar":"'تمكين تسجيل الدخول السريع سيسمح بالتحقق من خلال Face ID / Biometric الخاص بجهازك الحالي'"}, + "notNow": {"en": "Not Now", "ar":"ليس الآن"}, + + + }; diff --git a/lib/pages/login/saved_login.dart b/lib/pages/login/saved_login.dart index 50ebe25e..6d4a288c 100644 --- a/lib/pages/login/saved_login.dart +++ b/lib/pages/login/saved_login.dart @@ -4,21 +4,32 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:hmg_patient_app/config/config.dart'; import 'package:hmg_patient_app/config/shared_pref_kay.dart'; import 'package:hmg_patient_app/core/service/client/base_app_client.dart'; +import 'package:hmg_patient_app/core/viewModels/appointment_rate_view_model.dart'; import 'package:hmg_patient_app/core/viewModels/project_view_model.dart'; import 'package:hmg_patient_app/extensions/string_extensions.dart'; +import 'package:hmg_patient_app/locator.dart'; +import 'package:hmg_patient_app/models/Appointments/toDoCountProviderModel.dart'; import 'package:hmg_patient_app/models/Authentication/authenticated_user.dart'; import 'package:hmg_patient_app/models/Authentication/check_activation_code_response.dart'; +import 'package:hmg_patient_app/models/Authentication/check_paitent_authentication_req.dart'; import 'package:hmg_patient_app/models/Authentication/select_device_imei_res.dart'; +import 'package:hmg_patient_app/models/InPatientServices/get_admission_info_response_model.dart'; +import 'package:hmg_patient_app/models/InPatientServices/get_admission_request_info_response_model.dart'; import 'package:hmg_patient_app/new_ui/otp/otp_validation_bootmsheet_widget.dart'; import 'package:hmg_patient_app/pages/landing/landing_page.dart'; +import 'package:hmg_patient_app/pages/login/user-login-agreement-page.dart'; import 'package:hmg_patient_app/pages/login/welcome.dart'; +import 'package:hmg_patient_app/pages/rateAppointment/rate_appointment_doctor.dart'; import 'package:hmg_patient_app/services/authentication/auth_provider.dart' hide sharedPref; +import 'package:hmg_patient_app/services/clinic_services/get_clinic_service.dart'; import 'package:hmg_patient_app/uitl/app_toast.dart'; import 'package:hmg_patient_app/uitl/date_uitl.dart'; import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart'; import 'package:hmg_patient_app/uitl/translations_delegate_base.dart'; import 'package:hmg_patient_app/uitl/utils.dart' hide sharedPref; +import 'package:hmg_patient_app/widgets/otp/sms-popup.dart'; import 'package:hmg_patient_app/widgets/text/app_texts_widget.dart'; +import 'package:hmg_patient_app/widgets/transitions/fade_page.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; @@ -42,12 +53,14 @@ class _SavedLogin extends State { final authService = new AuthProvider(); late ProjectViewModel projectViewModel; + late ToDoCountProviderModel toDoProvider; + AppointmentRateViewModel appointmentRateViewModel = locator(); @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); - + toDoProvider = Provider.of(context); return Scaffold( backgroundColor: const Color(0xFFF8F8FA), body: SafeArea( @@ -168,7 +181,7 @@ class _SavedLogin extends State { onPressed: () { int? val = Utils.onOtpBtnPressed(OTPType.sms, phoneController); if (val != null) { - //checkUserAuthentication(val); + checkUserAuthentication(val); } }, backgroundColor: Colors.red, @@ -234,8 +247,8 @@ class _SavedLogin extends State { ), );}, - child: const Text( - 'Guest', + child: Text( + TranslationBase.of(context).guest, style: TextStyle( color: Color(0xFFED1C2B), fontSize: 16, @@ -254,8 +267,8 @@ class _SavedLogin extends State { ); }, - child: const Text( - 'Switch account', + child: Text( + TranslationBase.of(context).switchAccount, style: TextStyle( color: Color(0xFFED1C2B), fontSize: 16, @@ -350,7 +363,7 @@ class _SavedLogin extends State { // this.loginTokenID = result['LogInTokenID']; // this.patientOutSA = result['PatientOutSA']; // setDefault(); - checkActivationCode(lastLogin,result['LogInTokenID']); + checkActivationCode(null, lastLogin,result['LogInTokenID']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); @@ -359,8 +372,7 @@ class _SavedLogin extends State { } - checkActivationCode(int loginType, String loginToken) async { - + checkActivationCode(String? value, int loginType, String loginToken) async { AppGlobal.context = context; GifLoaderDialogUtils.showMyDialog(context); var request = authService.getCommonRequest( @@ -370,7 +382,7 @@ class _SavedLogin extends State { mobileNumber: int.parse(widget.savedLoginData.mobile!), zipCode: widget.savedLoginData.outSA == 1 ? '971' : '966', patientOutSA: widget.savedLoginData.outSA, - loginTokenID: loginToken, + loginTokenID: "", selectedOption: loginType, user: widget.savedLoginData, ).toJson(); @@ -401,7 +413,7 @@ class _SavedLogin extends State { { sharedPref.remove(FAMILY_FILE), result.list.isFamily = false, - // userData = result.list, + // userData = result.list, sharedPref.setString(BLOOD_TYPE, result.patientBloodType ?? ""), //Remove o+ from here Added by Aamir authenticatedUserObject.user = result.list, @@ -411,7 +423,7 @@ class _SavedLogin extends State { // loginTokenID = result.logInTokenID, await sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), await sharedPref.setString(TOKEN, result.authenticationTokenID), - // checkIfUserAgreedBefore(result), + checkIfUserAgreedBefore(result, loginType), projectViewModel.analytics.loginRegistration.login_successful(), } } @@ -431,6 +443,130 @@ class _SavedLogin extends State { }); } + checkIfUserAgreedBefore(CheckActivationCode result, int type) { + if (projectViewModel.havePrivilege(109)) { + this.authService.checkIfUserAgreed().then((result) { + if (result['IsPatientAlreadyAgreed']) { + goToHome(type); + } else { + this.authService.getUserAgreementContent().then((result) { + GifLoaderDialogUtils.hideDialog(AppGlobal.context); + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: UserLoginAgreementPage( + userAgreementText: result['UserAgreementContent'], + authenticatedUserObject: authenticatedUserObject, + appointmentRateViewModel: appointmentRateViewModel, + selectedOption: type, + isArabic: projectViewModel.isArabic, + ), + ), + (r) => false); + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); + print(err); + }); + } + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); + print(err); + }); + } else { + goToHome(type); + } + + // if (result.isNeedUserAgreement == true) { + // // move to agreement page. + // } else { + // goToHome(); + // } + } + + goToHome(int type) async { + authenticatedUserObject.isLogin = true; + appointmentRateViewModel.isLogin = true; + projectViewModel.isLogin = true; + projectViewModel.user = authenticatedUserObject.user; + await authenticatedUserObject.getUser(getUser: true); + + // GifLoaderDialogUtils.hideDialog(context); + getToDoCount(); + + checkIfIsInPatient() { + bool isAdmitted = false; + bool hasAdmissionRequest = false; + GetAdmissionInfoResponseModel getAdmissionInfoResponseModel; + GetAdmissionRequestInfoResponseModel getAdmissionRequestInfoResponseModel; + ClinicListService service = new ClinicListService(); + service.checkIfInPatientAPI(context).then((res) { + if (res['MessageStatus'] == 1) { + isAdmitted = res['isAdmitted']; + hasAdmissionRequest = res['hasAdmissionRequests']; + print("IS ADMITTED: $isAdmitted"); + print("Has Admission Request: $hasAdmissionRequest"); + if (isAdmitted) { + if (res['PatientAdmittedInformation'].length != 0) { + getAdmissionInfoResponseModel = GetAdmissionInfoResponseModel.fromJson(res['PatientAdmittedInformation'][0]); + projectViewModel.setInPatientProjectID(res['PatientAdmittedInformation'][0]['ProjectID']); + projectViewModel.setInPatientAdmissionInfo(getAdmissionInfoResponseModel); + projectViewModel.setIsPatientAdmitted(true); + } + } + if (hasAdmissionRequest) { + if (res['MedicalInstruction'].length != 0) { + getAdmissionRequestInfoResponseModel = GetAdmissionRequestInfoResponseModel.fromJson(res['MedicalInstruction'][0]); + // projectViewModel.setInPatientProjectID(res['MedicalInstruction'][0]['ProjectID']); + projectViewModel.setInPatientProjectID(res['MedicalInstruction'][0]['projectId']); + projectViewModel.setInPatientAdmissionRequest(getAdmissionRequestInfoResponseModel); + projectViewModel.setPatientHasAdmissionRequest(true); + } + } + } else {} + }); + }(); + appointmentRateViewModel + .getIsLastAppointmentRatedList(projectViewModel.isArabic ? 1 : 2) + .then((value) => { + GifLoaderDialogUtils.hideDialog(AppGlobal.context), + if (appointmentRateViewModel.isHaveAppointmentNotRate) + { + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: RateAppointmentDoctor(), + ), + (r) => false) + } + else + { + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: LandingPage(), + ), + (r) => false) + }, + insertIMEI(type) + }) + .catchError((err) { + print(err); + }); + } + + getToDoCount() { + toDoProvider.setState(0, 0, true, "0"); + ClinicListService service = new ClinicListService(); + service.getActiveAppointmentNo(context).then((res) { + if (res['MessageStatus'] == 1) { + toDoProvider.setState(res['AppointmentActiveNumber'], res['AncillaryOrderListCount'], true, "0"); + // toDoProvider.setState(res['AppointmentActiveNumber'], true, "0"); + } else {} + }).catchError((err) { + print(err); + }); + } + insertIMEI(lastLogin) { @@ -438,4 +574,95 @@ class _SavedLogin extends State { print(err); }); } + checkUserAuthentication(type) { + // showLoader(true); + GifLoaderDialogUtils.showMyDialog(context); + var req = this.authService.getCommonRequest(type: type, + registerd_data: null, + deviceToken: widget.savedLoginData.iMEI, + mobileNumber: int.parse(widget.savedLoginData.mobile!), + zipCode: widget.savedLoginData.outSA == 1 ? '971' : '966', + patientOutSA: widget.savedLoginData.outSA, + loginTokenID: "", + selectedOption: type, + user: widget.savedLoginData,); + + var request = CheckPatientAuthenticationReq.fromJson(req.toJson()); + + sharedPref.setObject(REGISTER_DATA_FOR_REGISTER, request); + authService + .checkPatientAuthentication(request) + .then((value) => { + GifLoaderDialogUtils.hideDialog(context), + 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, value['LogInTokenID']) + // }) + } + else + { + if (value['IsAuthenticated']) {this.checkActivationCode(null, type, value['LogInTokenID'])} + else { + AppToast.showErrorToast(message: value['errorMessage']), + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: WelcomeLogin(), + ), + (r) => false) + } + } + }) + .catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(context); + }); + } + + sendActivationCode(type, String loginToken) async { + var request = this.authService.getCommonRequest(type: type, + registerd_data: null, + deviceToken: widget.savedLoginData.iMEI, + mobileNumber: int.parse(widget.savedLoginData.mobile!), + zipCode: widget.savedLoginData.outSA == 1 ? '971' : '966', + patientOutSA: widget.savedLoginData.outSA, + loginTokenID: loginToken, + selectedOption: type, + user: widget.savedLoginData,); + request.sMSSignature = await SMSOTP.getSignature(); + GifLoaderDialogUtils.showMyDialog(context); + request.dob = ""; + request.healthId = ""; + request.isHijri = 0; + await this.authService.sendActivationCode(request).then((result) { + GifLoaderDialogUtils.hideDialog(context); + if (result != null && result['isSMSSent'] == true) { + this.startSMSService(type, loginToken); + } + }).catchError((r) { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: r.toString()); + }); + } + + var tempType; + + startSMSService(type, String loginToken) { + tempType = type; + SMSOTP( + context, + type, + phoneController.text, + (value) { + this.checkActivationCode(value, type, loginToken); + }, + () => { + Navigator.pop(context), + }, + ).displayDialog(context); + } } \ No newline at end of file diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index c8b93fd6..f1f2d17b 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -3481,7 +3481,12 @@ class TranslationBase { String get loginBy => localizedValues['loginBy'][locale.languageCode]; String get alreadyHaveAccount => localizedValues["alreadyHaveAccount"][locale.languageCode]; String get loginNow => localizedValues["loginNow"][locale.languageCode]; - + String get guest => localizedValues["guest"][locale.languageCode]; + String get switchAccount => localizedValues["switchAccount"][locale.languageCode]; + String get allSet => localizedValues["allSet"][locale.languageCode]; + String get enableQuickLogin => localizedValues["enableQuickLogin"][locale.languageCode]; + String get enableMsg => localizedValues["enableMsg"][locale.languageCode]; + String get notNow => localizedValues["notNow"][locale.languageCode]; } diff --git a/lib/widgets/quick_login.dart b/lib/widgets/quick_login.dart index ae57f2af..110f9636 100644 --- a/lib/widgets/quick_login.dart +++ b/lib/widgets/quick_login.dart @@ -42,10 +42,8 @@ class _QuickLoginBottomSheet extends State { }, child: SvgPicture.asset("assets/images/svg/cross-circle.svg", width: 24, height: 24)),],), Utils.showLottie(context: context, assetPath: 'assets/animations/lottie/checkmark.json', width: 120, height: 120, repeat: true), - - - const Text( - 'All Set! Now you can login with Face ID or Biometric', + Text( + TranslationBase.of(context).allSet, textAlign: TextAlign.center, style: TextStyle( fontSize: 16, @@ -63,8 +61,8 @@ class _QuickLoginBottomSheet extends State { Image.asset("assets/images/lock-icon.png", height: 101,), const SizedBox(height: 10), - const Text( - 'Enable Quick Login', + Text( + TranslationBase.of(context).enableQuickLogin, style: TextStyle( fontSize: 26, fontWeight: FontWeight.bold, @@ -75,8 +73,8 @@ class _QuickLoginBottomSheet extends State { const SizedBox(height: 5), // Description - const Text( - 'Enabling the quick login will verify through your existing device Face ID / Biometric', + Text( + TranslationBase.of(context).enableMsg, style: TextStyle( fontSize: 16, color: Color(0xFF666666), @@ -95,7 +93,7 @@ class _QuickLoginBottomSheet extends State { Expanded(child: CustomButton( - text: "Enable Quick Login", + text:TranslationBase.of(context).enableQuickLogin, onPressed:widget.onPressed, backgroundColor:Color(0xffED1C2B), borderColor:Color(0xffED1C2B), @@ -111,7 +109,7 @@ class _QuickLoginBottomSheet extends State { Expanded(child: CustomButton( - text: "Not Now", + text:TranslationBase.of(context).notNow, onPressed: (){ Navigator.pop(context);}, backgroundColor:Color(0xffFEE9EA), borderColor:Color(0xffFEE9EA),