From 2a081e30b5e2a7e4d17f99eb1e56fe0ae0f4eacb Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Tue, 9 Sep 2025 18:50:40 +0300 Subject: [PATCH] saved login done. --- lib/core/api_consts.dart | 2 +- lib/core/app_state.dart | 2 +- lib/core/utils/request_utils.dart | 3 +- .../authentication/authentication_repo.dart | 33 +++++++++++++-- .../authentication_view_model.dart | 40 +++++++++++-------- .../patient_insert_device_imei_request.dart | 13 +++--- .../authentication/quick_login.dart | 6 ++- .../authentication/saved_login_screen.dart | 6 ++- lib/presentation/home/landing_page.dart | 11 +++-- lib/widgets/common_bottom_sheet.dart | 2 +- 10 files changed, 83 insertions(+), 35 deletions(-) diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index a034570..f5c19e0 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -726,7 +726,7 @@ const DEACTIVATE_ACCOUNT = 'Services/Patients.svc/REST/PatientAppleActivation_In class ApiConsts { static const maxSmallScreen = 660; - static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.uat; + static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.prod; // static String baseUrl = 'https://uat.hmgwebservices.com/'; // HIS API URL UAT diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index 4408844..4ab98f6 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -109,7 +109,7 @@ class AppState { RegistrationDataModelPayload? _userRegistrationPayload; - RegistrationDataModelPayload get getUserRegistrationPayload => _userRegistrationPayload!; + RegistrationDataModelPayload get getUserRegistrationPayload => _userRegistrationPayload ?? RegistrationDataModelPayload(); set setUserRegistrationPayload(RegistrationDataModelPayload value) { _userRegistrationPayload = value; diff --git a/lib/core/utils/request_utils.dart b/lib/core/utils/request_utils.dart index 1045d9c..1bf1e06 100644 --- a/lib/core/utils/request_utils.dart +++ b/lib/core/utils/request_utils.dart @@ -61,6 +61,7 @@ class RequestUtils { int? patientId, required String nationIdText, required String countryCode, + required int loginType }) { bool fileNo = false; if (nationIdText.isNotEmpty) { @@ -71,7 +72,7 @@ class RequestUtils { request.mobileNo = '0$phoneNumber'; request.deviceToken = deviceToken; request.projectOutSA = patientOutSA; - request.loginType = otpTypeEnum.toInt(); + request.loginType = loginType; request.oTPSendType = otpTypeEnum.toInt(); // could map OTPTypeEnum if needed request.zipCode = countryCode; // or countryCode if defined elsewhere request.logInTokenID = loginTokenID ?? ""; diff --git a/lib/features/authentication/authentication_repo.dart b/lib/features/authentication/authentication_repo.dart index 222ac7c..989c667 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -180,6 +180,7 @@ class AuthenticationRepoImp implements AuthenticationRepo { newRequest.projectOutSA = newRequest.zipCode == '966' ? false : true; newRequest.isDentalAllowedBackend = false; newRequest.forRegisteration = newRequest.isRegister ?? false; + newRequest.isRegister = false; } @@ -390,8 +391,34 @@ class AuthenticationRepoImp implements AuthenticationRepo { @override Future> insertPatientDeviceData({required patientDeviceDataRequest}) { - // TODO: implement insertPatientDeviceData - - throw UnimplementedError(); + try { + GenericApiModel? apiResponse; + Failure? failure; + return apiClient.post( + ApiConsts.insertPatientMobileData, + body: patientDeviceDataRequest, + onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, + onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: errorMessage, + data: response, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, + ).then((_) { + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + }); + } catch (e) { + return Future.value(Left(UnknownFailure(e.toString()))); + } } } diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 097079a..eeccfc8 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -289,7 +289,7 @@ class AuthenticationViewModel extends ChangeNotifier { await checkActivationCode( otpTypeEnum: otpTypeEnum, onWrongActivationCode: (String? message) {}, - activationCode: 0000, + activationCode: null, //todo silent login case halded on the repo itself.. ); } } @@ -360,7 +360,7 @@ class AuthenticationViewModel extends ChangeNotifier { } Future checkActivationCode({ - required int activationCode, + required String? activationCode, required OTPTypeEnum otpTypeEnum, required Function(String? message) onWrongActivationCode, }) async { @@ -373,9 +373,10 @@ class AuthenticationViewModel extends ChangeNotifier { registeredData: null, nationIdText: nationalIdController.text, countryCode: selectedCountrySignup.countryCode, + loginType: loginTypeEnum.toInt ).toJson(); - bool isForRegister = _appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true; + bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true); if (isForRegister) { if (_appState.getUserRegistrationPayload.patientOutSa == true) request['DOB'] = _appState.getUserRegistrationPayload.dob; request['HealthId'] = _appState.getUserRegistrationPayload.healthId; @@ -396,7 +397,7 @@ class AuthenticationViewModel extends ChangeNotifier { } else { final resultEither = await _authenticationRepo.checkActivationCodeRepo( newRequest: CheckActivationCodeRegisterReq.fromJson(request), - activationCode: activationCode.toString(), + activationCode: activationCode, isRegister: false, ); @@ -422,6 +423,7 @@ class AuthenticationViewModel extends ChangeNotifier { _appState.setAppAuthToken = activation.authenticationTokenId; final request = RequestUtils.getAuthanticatedCommonRequest().toJson(); bool isUserAgreedBefore = await checkIfUserAgreedBefore(request: request); + insertPatientIMEIData(loginTypeEnum.toInt); clearDefaultInputValues(); if (isUserAgreedBefore) { navigateToHomeScreen(); @@ -491,7 +493,7 @@ class AuthenticationViewModel extends ChangeNotifier { phoneNumber: phoneNumber, checkActivationCode: (int activationCode) async { await checkActivationCode( - activationCode: activationCode, + activationCode: activationCode.toString(), otpTypeEnum: otpTypeEnum, onWrongActivationCode: (String? value) { onWrongActivationCode(message: value); @@ -508,12 +510,19 @@ class AuthenticationViewModel extends ChangeNotifier { } loginWithFingerPrintFace() async { - _localAuthService.authenticate().then((value) { + _localAuthService.authenticate().then((value) async { if (value) { // we have to handle this if verification true; - // checkActivationCode(otpTypeEnum: OTPTypeEnum.faceIDFingerprint, activationCode: 0000, onWrongActivationCode: (String? message) {}); - // authenticated = true; - insertPatientIMEIData( OTPTypeEnum.faceIDFingerprint.toInt()); + if(!_appState.isAuthenticated) { + loginTypeEnum = (_appState.deviceTypeID == 1 ? LoginTypeEnum.face : LoginTypeEnum.fingerprint); + print(loginTypeEnum); + checkActivationCode(otpTypeEnum:OTPTypeEnum.faceIDFingerprint , activationCode: null, onWrongActivationCode: (String? message) {}); + insertPatientIMEIData((_appState.deviceTypeID == 1 ? LoginTypeEnum.face.toInt : LoginTypeEnum.fingerprint.toInt)); + }else { + // authenticated = true; + insertPatientIMEIData((_appState.deviceTypeID == 1 ? LoginTypeEnum.face.toInt : LoginTypeEnum.fingerprint.toInt)); + } + notifyListeners(); // navigateToHomeScreen(); } else { @@ -521,7 +530,6 @@ class AuthenticationViewModel extends ChangeNotifier { notifyListeners(); } }); - notifyListeners(); } checkLastLoginStatus(Function() onSuccess) async { @@ -696,25 +704,25 @@ class AuthenticationViewModel extends ChangeNotifier { Future insertPatientIMEIData(int loginType) async{ - final resultEither = await _authenticationRepo.insertPatientIMEIData(patientIMEIDataRequest: PatientInsertDeviceImei(imei: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientIdentificationNo:_appState.getAuthenticatedUser()!.nationalityId!, firstName: _appState.getAuthenticatedUser()!.firstName!, lastName: _appState.getAuthenticatedUser()!.lastName!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, mobileNo:_appState.getAuthenticatedUser()!.mobileNumber!, logInTypeId: loginType, patientOutSa:_appState.getAuthenticatedUser()!.outSa! ).toJson()); + final resultEither = await _authenticationRepo.insertPatientIMEIData(patientIMEIDataRequest: PatientInsertDeviceImei(imei: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientIdentificationNo:_appState.getAuthenticatedUser()!.nationalityId!, firstName: _appState.getAuthenticatedUser()!.firstName!, lastName: _appState.getAuthenticatedUser()!.lastName!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, mobileNo:_appState.getAuthenticatedUser()!.mobileNumber!, logInTypeId: loginType, patientOutSa:_appState.getAuthenticatedUser()!.outSa!, outSa: _appState.getAuthenticatedUser()!.outSa == 1 ? true :false, biometricEnabled: loginType == 1 || loginType ==2 ? false :true, firstNameN:_appState.getAuthenticatedUser()!.firstNameN , lastNameN:_appState.getAuthenticatedUser()!.lastNameN ).toJson()); resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { if (apiResponse.messageStatus == 1) { - print("Insert IMEI Success"); + log("Insert IMEI Success"); insertPatientDeviceData( loginType); } else { - print("Insert IMEI Failed"); + log("Insert IMEI Failed"); } }); } Future insertPatientDeviceData(int loginType) async{ - final resultEither = await _authenticationRepo.insertPatientDeviceData(patientDeviceDataRequest: InsertPatientMobileDeviceInfo(deviceToken: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, patientOutSa:_appState.getAuthenticatedUser()!.outSa!, loginType: loginType, languageId: _appState.getLanguageID(), latitude: _appState.userLat, longitude:_appState.userLong ).toJson()); + final resultEither = await _authenticationRepo.insertPatientDeviceData(patientDeviceDataRequest: InsertPatientMobileDeviceInfo(deviceToken: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, patientOutSa:_appState.getAuthenticatedUser()!.outSa!, loginType: loginType, languageId: _appState.getLanguageID(), latitude: _appState.userLat, longitude:_appState.userLong, voipToken: "", deviceType: _appState.deviceTypeID, patientMobileNumber:_appState.getAuthenticatedUser()!.mobileNumber, nationalId: _appState.getAuthenticatedUser()!.patientIdentificationNo, gender: _appState.getAuthenticatedUser()!.gender ).toJson()); resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { if (apiResponse.messageStatus == 1) { - print("Insert Device Data Success"); + log("Insert Device Data Success"); } else { - print("Insert IMEI Failed"); + log("Insert IMEI Failed"); } }); diff --git a/lib/features/authentication/models/request_models/patient_insert_device_imei_request.dart b/lib/features/authentication/models/request_models/patient_insert_device_imei_request.dart index f54bb83..0b2a99f 100644 --- a/lib/features/authentication/models/request_models/patient_insert_device_imei_request.dart +++ b/lib/features/authentication/models/request_models/patient_insert_device_imei_request.dart @@ -7,7 +7,6 @@ class PatientInsertDeviceImei { String? firstName; String? firstNameN; String? lastNameN; - String? lastName; int? preferredLanguage; String? patientIdentificationNo; bool? outSa; @@ -28,6 +27,7 @@ class PatientInsertDeviceImei { int? patientTypeId; int? patientOutSa; String? sessionId; + String? lastName; PatientInsertDeviceImei({ this.setupId, @@ -36,7 +36,6 @@ class PatientInsertDeviceImei { this.firstName, this.firstNameN, this.lastNameN, - this.lastName, this.preferredLanguage, this.patientIdentificationNo, this.outSa, @@ -57,6 +56,7 @@ class PatientInsertDeviceImei { this.patientTypeId, this.patientOutSa, this.sessionId, + this.lastName }); factory PatientInsertDeviceImei.fromRawJson(String str) => PatientInsertDeviceImei.fromJson(json.decode(str)); @@ -70,7 +70,6 @@ class PatientInsertDeviceImei { firstName: json["FirstName"], firstNameN: json["FirstNameN"], lastNameN: json["LastNameN"], - lastName: json["LastName"], preferredLanguage: json["PreferredLanguage"], patientIdentificationNo: json["PatientIdentificationNo"], outSa: json["OutSA"], @@ -90,7 +89,9 @@ class PatientInsertDeviceImei { deviceTypeId: json["DeviceTypeID"], patientTypeId: json["PatientTypeID"], patientOutSa: json["PatientOutSA"], - sessionId: json[" SessionID"], + sessionId: json["SessionID"], + lastName: json["LastName"], + ); Map toJson() => { @@ -100,7 +101,6 @@ class PatientInsertDeviceImei { "FirstName": firstName, "FirstNameN": firstNameN, "LastNameN": lastNameN, - "LastName": lastName, "PreferredLanguage": preferredLanguage, "PatientIdentificationNo": patientIdentificationNo, "OutSA": outSa, @@ -120,6 +120,7 @@ class PatientInsertDeviceImei { "DeviceTypeID": deviceTypeId, "PatientTypeID": patientTypeId, "PatientOutSA": patientOutSa, - " SessionID": sessionId, + "SessionID": sessionId, + "LastName": lastName, }; } diff --git a/lib/presentation/authentication/quick_login.dart b/lib/presentation/authentication/quick_login.dart index 9cf0431..c5f540b 100644 --- a/lib/presentation/authentication/quick_login.dart +++ b/lib/presentation/authentication/quick_login.dart @@ -19,6 +19,7 @@ class QuickLogin extends StatefulWidget { } class _QuickLogin extends State { + @override Widget build(BuildContext context) { return Container( @@ -70,7 +71,7 @@ class _QuickLogin extends State { height: 101, ), const SizedBox(height: 10), - LocaleKeys.enableQuickLogin.tr().toText26(isBold: true), + LocaleKeys.enableQuickLogin.tr().toText26(isBold: true), // Text( // ' TranslationBase.of(context).enableQuickLogin', // style: context.dynamicTextStyle( @@ -100,6 +101,9 @@ class _QuickLogin extends State { text:LocaleKeys.enableQuickLogin.tr(), onPressed: () { widget.onPressed(); + setState(() { + + }); }, backgroundColor: Color(0xffED1C2B), borderColor: Color(0xffED1C2B), diff --git a/lib/presentation/authentication/saved_login_screen.dart b/lib/presentation/authentication/saved_login_screen.dart index bf97987..55cbadf 100644 --- a/lib/presentation/authentication/saved_login_screen.dart +++ b/lib/presentation/authentication/saved_login_screen.dart @@ -34,6 +34,8 @@ class _SavedLogin extends State { void initState() { authVm = context.read(); appState = getIt.get(); + loginType = LoginTypeExtension.fromValue(appState.getSelectDeviceByImeiRespModelElement!.logInType!)!; + authVm.phoneNumberController.text = appState.getSelectDeviceByImeiRespModelElement!.mobile!.startsWith("0") ? appState.getSelectDeviceByImeiRespModelElement!.mobile!.replaceFirst("0", "") : appState.getSelectDeviceByImeiRespModelElement!.mobile!; @@ -78,7 +80,7 @@ class _SavedLogin extends State { children: [ // Last login info - ("${LocaleKeys.lastloginBy.tr()} ${LoginTypeExtension.fromValue(appState.getSelectDeviceByImeiRespModelElement!.logInType ?? 0)!.displayName}") + ("${LocaleKeys.lastloginBy.tr()} ${loginType.displayName}") .toText14(isBold: true, color: AppColors.greyTextColor), (appState.getSelectDeviceByImeiRespModelElement!.createdOn != null ? DateUtil.getFormattedDate(DateUtil.convertStringToDate(appState.getSelectDeviceByImeiRespModelElement!.createdOn!), "d MMMM, y 'at' HH:mm") @@ -87,7 +89,7 @@ class _SavedLogin extends State { Container( margin: EdgeInsets.all(16.h), - child: Utils.buildSvgWithAssets(icon: getTypeIcons(loginType.toInt), height: 54, width: 54, iconColor: loginType.toInt == 4 ? null : AppColors.primaryRedColor)), + child: Utils.buildSvgWithAssets(icon: getTypeIcons(appState.getSelectDeviceByImeiRespModelElement!.logInType!), height: 54, width: 54, iconColor: loginType.toInt == 4 ? null : AppColors.primaryRedColor)), // Face ID login button SizedBox( height: 45, diff --git a/lib/presentation/home/landing_page.dart b/lib/presentation/home/landing_page.dart index a9ced9c..b55632b 100644 --- a/lib/presentation/home/landing_page.dart +++ b/lib/presentation/home/landing_page.dart @@ -326,15 +326,20 @@ class _LandingPageState extends State { context, title: "", child: QuickLogin( - isDone: isDone, + isDone: isDone, onPressed: () { // sharedPref.setBool(HAS_ENABLED_QUICK_LOGIN, true); authVM.loginWithFingerPrintFace(); }, ), - height: 400, + height:isDone == false ? ResponsiveExtension.screenHeight * 0.5 : ResponsiveExtension.screenHeight * 0.3, isFullScreen: false, - callBackFunc: (str) {}, + callBackFunc: (str) { + isDone = true; + setState(() { + + }); + }, ); } } diff --git a/lib/widgets/common_bottom_sheet.dart b/lib/widgets/common_bottom_sheet.dart index 11b7df8..583eab6 100644 --- a/lib/widgets/common_bottom_sheet.dart +++ b/lib/widgets/common_bottom_sheet.dart @@ -54,7 +54,7 @@ class ButtonSheetContent extends StatelessWidget { @override Widget build(BuildContext context) { return Column( - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, children: [ // SizedBox( // height: 20.h,