From 572fcef0f1751879de0fb1464a484f1e5a8ab7a3 Mon Sep 17 00:00:00 2001 From: faizatflutter Date: Tue, 2 Sep 2025 17:00:29 +0300 Subject: [PATCH] checkUserAuth --- lib/core/app_state.dart | 23 ++-- .../authentication_view_model.dart | 126 +++++------------- .../home/data/landing_page_data.dart | 2 - 3 files changed, 48 insertions(+), 103 deletions(-) diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index 7c42042..fbd8e0f 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -14,21 +14,28 @@ class AppState { set setIsAuthenticated(v) => isAuthenticated = v; - set setAppAuthToken(v) => appAuthToken = v; - String appAuthToken = ""; + set setAppAuthToken(v) => appAuthToken = v; + set setUserLat(v) => userLat = v; set setUserLong(v) => userLong = v; + // TODO: GETTER SETTER FOR SESSION ID + + String sessionId = ""; + + set setSessionId(v) => sessionId = v; + final PostParamsModel _postParamsInitConfig = PostParamsModel( - channel: 3, - versionID: ApiConsts.VERSION_ID, - ipAddress: '10.20.10.20', - generalId: 'Cs2020@2016\$2958', - deviceTypeID: "2", - sessionID: 'TMRhVmkGhOsvamErw'); + channel: 3, + versionID: ApiConsts.VERSION_ID, + ipAddress: '10.20.10.20', + generalId: 'Cs2020@2016\$2958', + deviceTypeID: "2", + sessionID: 'TMRhVmkGhOsvamErw', + ); void setPostParamsInitConfig() { isAuthenticated = false; diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index ed77aca..c519311 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -24,14 +24,14 @@ class AuthenticationViewModel extends ChangeNotifier { final TextEditingController phoneNumberController = TextEditingController(); Future selectDeviceImei({Function(dynamic)? onSuccess, Function(String)? onError}) async { - String firebaseToken = - "dOGRRszQQMGe_9wA5Hx3kO:APA91bFV5IcIJXvcCXXk0tc2ddtZgWwCPq7sGSuPr-YW7iiJpQZKgFGN9GAzCVOWL8MfheaP1slE8MdxB7lczdPBGdONQ7WbMmhgHcsUCUktq-hsapGXXqc"; + String firebaseToken = "dOGRRszQQMGe_9wA5Hx3kO:APA91bFV5IcIJXvcCXXk0tc2ddtZgWwCPq7sGSuPr-YW7iiJpQZKgFGN9GAzCVOWL8MfheaP1slE8MdxB7lczdPBGdONQ7WbMmhgHcsUCUktq-hsapGXXqc"; final result = await authenticationRepo.selectDeviceByImei(firebaseToken: firebaseToken); result.fold( (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { + //TODO: NEXT CREATION dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); } else if (apiResponse.messageStatus == 1) { //todo: move to next api call @@ -40,96 +40,36 @@ class AuthenticationViewModel extends ChangeNotifier { ); } - // Future checkUserAuthentication({Function(dynamic)? onSuccess, Function(String)? onError}) async { - // CheckPatientAuthenticationReq checkPatientAuthenticationReq = RequestUtils.getCommonRequestWelcome( - // phoneNumber: '0567184134', - // otpTypeEnum: OTPTypeEnum.sms, - // deviceToken: 'dummyDeviceToken123', - // patientOutSA: true, - // loginTokenID: 'dummyLoginToken456', - // registeredData: null, - // patientId: 12345, - // nationIdText: '1234567890', - // countryCode: 'SA', - // ); - // - // final result = await authenticationRepo.checkPatientAuthentication(checkPatientAuthenticationReq: checkPatientAuthenticationReq); - // result.fold( - // (failure) async => await errorHandlerService.handleError(failure: failure), - // (apiResponse) { - // if (apiResponse.data['isSMSSent']) { - // // TODO: set this in AppState - // // sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']); - // // loginTokenID = value['LogInTokenID'], - // // sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), - // sendActivationCode(type); - // } else { - // if (apiResponse.data['IsAuthenticated']) { - // checkActivationCode(onWrongActivationCode: (String? message) {}); - // } - // } - // }, - // ); - // } + Future checkUserAuthentication({OTPTypeEnum otpTypeEnum, Function(dynamic)? onSuccess, Function(String)? onError}) async { + CheckPatientAuthenticationReq checkPatientAuthenticationReq = RequestUtils.getCommonRequestWelcome( + phoneNumber: '0567184134', + otpTypeEnum: OTPTypeEnum.sms, + deviceToken: 'dummyDeviceToken123', + patientOutSA: true, + loginTokenID: 'dummyLoginToken456', + registeredData: null, + patientId: 12345, + nationIdText: '1234567890', + countryCode: 'SA', + ); + + final result = await authenticationRepo.checkPatientAuthentication(checkPatientAuthenticationReq: checkPatientAuthenticationReq); + result.fold( + (failure) async => await errorHandlerService.handleError(failure: failure), + (apiResponse) { + if (apiResponse.data['isSMSSent']) { + // TODO: set this in AppState + // sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']); + // loginTokenID = value['LogInTokenID'], + // sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), + sendActivationCode(otpTypeEnum: otpTypeEnum); + } else { + if (apiResponse.data['IsAuthenticated']) { + checkActivationCode(onWrongActivationCode: (String? message) {}); + } + } + }, + ); + } - // Future sendActivationCode({required OTPTypeEnum otpTypeEnum}) async { - // var request = RequestUtils.getCommonRequestAuthProvider( - // otpTypeEnum: otpTypeEnum, - // registeredData: null, - // deviceToken: "dummyLoginToken456", - // mobileNumber: "0567184134", - // zipCode: "SA", - // patientOutSA: true, - // loginTokenID: "dummyLoginToken456", - // selectedOption: selectedOption, - // patientId: 12345, - // ); - // - // request.sMSSignature = await SMSOTP.getSignature(); - // selectedOption = type; - // // GifLoaderDialogUtils.showMyDialog(context); - // if (healthId != null || isDubai) { - // if (!isDubai) { - // request.dob = dob; //isHijri == 1 ? dob : dateFormat2.format(dateFormat.parse(dob)); - // } - // request.healthId = healthId; - // request.isHijri = isHijri; - // await this.apiClient.sendActivationCodeRegister(request).then((result) { - // // GifLoaderDialogUtils.hideDialog(context); - // if (result != null && result['isSMSSent'] == true) { - // this.startSMSService(type); - // } - // }).catchError((r) { - // GifLoaderDialogUtils.hideDialog(context); - // context.showBottomSheet( - // child: ExceptionBottomSheet( - // message: r.toString(), - // onOkPressed: () { - // Navigator.of(context).pop(); - // }, - // )); - // // AppToast.showErrorToast(message: r); - // }); - // } else { - // 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); - // } - // }).catchError((r) { - // GifLoaderDialogUtils.hideDialog(context); - // context.showBottomSheet( - // child: ExceptionBottomSheet( - // message: r.toString(), - // onOkPressed: () { - // Navigator.of(context).pop(); - // }, - // )); - // // AppToast.showErrorToast(message: r.toString()); - // }); - // } - // } } diff --git a/lib/presentation/home/data/landing_page_data.dart b/lib/presentation/home/data/landing_page_data.dart index af43b9f..b34d9bc 100644 --- a/lib/presentation/home/data/landing_page_data.dart +++ b/lib/presentation/home/data/landing_page_data.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/presentation/home/data/service_card_data.dart';