fixes for login & register (Points)
parent
fd0635764d
commit
bdaef7f89c
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,484 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:hmg_patient_app/config/config.dart';
|
||||
// import 'package:hmg_patient_app/core/enum/viewstate.dart';
|
||||
// import 'package:hmg_patient_app/core/service/AuthenticatedUserObject.dart';
|
||||
// import 'package:hmg_patient_app/core/viewModels/appointment_rate_view_model.dart';
|
||||
// import 'package:hmg_patient_app/core/viewModels/base_view_model.dart';
|
||||
// import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
|
||||
// import 'package:hmg_patient_app/locator.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/Authentication/send_activation_request.dart';
|
||||
// import 'package:hmg_patient_app/services/authentication/auth_provider.dart';
|
||||
// import 'package:hmg_patient_app/uitl/app_shared_preferences.dart';
|
||||
// import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart';
|
||||
// import 'package:hmg_patient_app/uitl/utils.dart';
|
||||
// import 'package:hmg_patient_app/config/shared_pref_kay.dart';
|
||||
// import 'package:hmg_patient_app/pages/landing/landing_page.dart';
|
||||
// import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
|
||||
// import 'package:hmg_patient_app/new_ui/otp/otp_validation_bootmsheet_widget.dart';
|
||||
// import 'package:hmg_patient_app/theme/colors.dart';
|
||||
// import 'package:hmg_patient_app/widgets/text/app_texts_widget.dart';
|
||||
// import 'package:intl/src/intl/date_format.dart';
|
||||
// import '../../models/Appointments/toDoCountProviderModel.dart';
|
||||
// import '../../models/InPatientServices/get_admission_info_response_model.dart';
|
||||
// import '../../models/InPatientServices/get_admission_request_info_response_model.dart';
|
||||
// import '../../pages/login/register_new.dart';
|
||||
// import '../../pages/login/user-login-agreement-page.dart';
|
||||
// import '../../pages/login/welcome.dart';
|
||||
// import '../../pages/rateAppointment/rate_appointment_doctor.dart';
|
||||
// import '../../services/clinic_services/get_clinic_service.dart';
|
||||
// import '../../uitl/app_toast.dart';
|
||||
// import '../../uitl/translations_delegate_base.dart';
|
||||
// import '../../widgets/dialogs/confirm_dialog.dart';
|
||||
// import '../../widgets/otp/sms-popup.dart';
|
||||
//
|
||||
import 'base_view_model.dart';
|
||||
|
||||
class AuthProviderViewModel extends BaseViewModel {
|
||||
// bool isLoading = true;
|
||||
// TextEditingController nationIdController = TextEditingController();
|
||||
// TextEditingController? phoneController = TextEditingController();
|
||||
// String? phoneNumber;
|
||||
// Country selectedCountry = Country.saudiArabia;
|
||||
// bool isDubai = false;
|
||||
// final authService = AuthProvider();
|
||||
// var sharedPref = AppSharedPreferences();
|
||||
// bool authenticated = false;
|
||||
// late int mobileNumber;
|
||||
// String errorMsg = '';
|
||||
// SelectDeviceIMEIRES? userDetails;
|
||||
// var registerd_data;
|
||||
// bool isMoreOption = false;
|
||||
// var zipCode;
|
||||
// var patientOutSA;
|
||||
// var loginTokenID;
|
||||
// var loginType;
|
||||
// var deviceToken;
|
||||
// var lastLogin;
|
||||
// AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
|
||||
// AppointmentRateViewModel appointmentRateViewModel = locator<AppointmentRateViewModel>();
|
||||
// ProjectViewModel projectViewModel = locator<ProjectViewModel>();
|
||||
// ToDoCountProviderModel toDoProvider = locator<ToDoCountProviderModel>();
|
||||
// late int selectedOption;
|
||||
// bool onlySMSBox = false;
|
||||
// var userData;
|
||||
// int fingrePrintBefore = 0;
|
||||
// var dob;
|
||||
// late int isHijri;
|
||||
// var healthId;
|
||||
//
|
||||
// checkUserAuthentication(type, context) {
|
||||
// GifLoaderDialogUtils.showMyDialog(context);
|
||||
// var req = getCommonRequest(type: type);
|
||||
// req.logInTokenID = "";
|
||||
// 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']),
|
||||
// loginTokenID = value['LogInTokenID'],
|
||||
// sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request),
|
||||
// sendActivationCode(type, context)
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (value['IsAuthenticated']) {checkActivationCode(value: null, context: context)}
|
||||
// }
|
||||
// })
|
||||
// .catchError((err) {
|
||||
// print(err);
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// ConfirmDialog dialog = ConfirmDialog(
|
||||
// context: context,
|
||||
// confirmMessage: err,
|
||||
// okText: TranslationBase.of(context).confirm,
|
||||
// cancelText: TranslationBase.of(context).cancel_nocaps,
|
||||
// okFunction: () => {
|
||||
// ConfirmDialog.closeAlertDialog(context),
|
||||
// Navigator.of(context).push(FadePage(page: RegisterNew())),
|
||||
// },
|
||||
// cancelFunction: () => {});
|
||||
// dialog.showAlertDialog(context);
|
||||
// projectViewModel.analytics.loginRegistration.login_fail(error: err.toString());
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// sendActivationCode(type, context) async {
|
||||
// var request = getCommonRequest(type: type);
|
||||
// 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 authService.sendActivationCodeRegister(request).then((result) {
|
||||
// // GifLoaderDialogUtils.hideDialog(context);
|
||||
// if (result != null && result['isSMSSent'] == true) {
|
||||
// startSMSService(type, context);
|
||||
// }
|
||||
// }).catchError((r) {
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// AppToast.showErrorToast(message: r);
|
||||
// });
|
||||
// } else {
|
||||
// request.dob = "";
|
||||
// request.healthId = "";
|
||||
// request.isHijri = 0;
|
||||
// await authService.sendActivationCode(request).then((result) {
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// if (result != null && result['isSMSSent'] == true) {
|
||||
// startSMSService(type, context);
|
||||
// }
|
||||
// }).catchError((r) {
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// AppToast.showErrorToast(message: r.toString());
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// checkActivationCode({value, context}) async {
|
||||
// // Navigator.pop(context);
|
||||
// GifLoaderDialogUtils.showMyDialog(context!);
|
||||
// var request = getCommonRequest().toJson();
|
||||
// dynamic res;
|
||||
// if (healthId != null || isDubai) {
|
||||
// if (isDubai) {
|
||||
// request['DOB'] = dob;
|
||||
// }
|
||||
// request['HealthId'] = healthId;
|
||||
// request['IsHijri'] = isHijri;
|
||||
//
|
||||
// authService
|
||||
// .checkActivationCodeRegister(request, value)
|
||||
// .then((result) => {
|
||||
// res = result,
|
||||
// if (result is Map)
|
||||
// {
|
||||
// result = CheckActivationCode.fromJson(result as Map<String, dynamic>),
|
||||
// if (registerd_data != null && registerd_data.isRegister == true)
|
||||
// {
|
||||
// // if(widget.isDubai ==false){
|
||||
// // widget.changePageViewIndex!(1),
|
||||
// // if(widget.isDubai ==false){
|
||||
//
|
||||
// Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)),
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Navigator.of(context).pop(),
|
||||
// GifLoaderDialogUtils.hideDialog(context),
|
||||
// Future.delayed(Duration(seconds: 1), () {
|
||||
// AppToast.showErrorToast(message: result);
|
||||
// }),
|
||||
// // projectViewModel.analytics.loginRegistration.login_fail(error: result),
|
||||
// // projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result),
|
||||
// }
|
||||
// })
|
||||
// .catchError((err) {
|
||||
// print(err);
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// Future.delayed(Duration(seconds: 1), () {
|
||||
// AppToast.showErrorToast(message: err);
|
||||
// // startSMSService(tempType);
|
||||
// });
|
||||
// });
|
||||
// } else {
|
||||
// authService
|
||||
// .checkActivationCode(request, value)
|
||||
// .then((result) async => {
|
||||
// res = result,
|
||||
// if (result is Map)
|
||||
// {
|
||||
// result = CheckActivationCode.fromJson(result as Map<String, dynamic>),
|
||||
// if (result.errorCode == '699')
|
||||
// {
|
||||
// //699 block run here
|
||||
// GifLoaderDialogUtils.hideDialog(context),
|
||||
// Future.delayed(Duration(seconds: 2), () {
|
||||
// AppToast.showErrorToast(message: result.errorEndUserMessage);
|
||||
// Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin));
|
||||
// })
|
||||
// }
|
||||
// else if (registerd_data != null && registerd_data.isRegister == true)
|
||||
// {
|
||||
// // widget.changePageViewIndex!(1),
|
||||
// Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)),
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sharedPref.remove(FAMILY_FILE),
|
||||
// result.list.isFamily = false,
|
||||
// projectViewModel.user = userData = result.list,
|
||||
// sharedPref.setString(BLOOD_TYPE, result.patientBloodType ?? ""),
|
||||
// authenticatedUserObject.user = result.list,
|
||||
// projectViewModel.setPrivilege(privilegeList: res),
|
||||
// await sharedPref.setObject(MAIN_USER, result.list),
|
||||
// await sharedPref.setObject(USER_PROFILE, result.list),
|
||||
// loginTokenID = result.logInTokenID,
|
||||
// await sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID),
|
||||
// await sharedPref.setString(TOKEN, result.authenticationTokenID),
|
||||
// checkIfUserAgreedBefore(result, context),
|
||||
// projectViewModel.analytics.loginRegistration.login_successful(),
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Navigator.of(context).pop(),
|
||||
// GifLoaderDialogUtils.hideDialog(context),
|
||||
// Future.delayed(Duration(seconds: 1), () {
|
||||
// Navigator.of(context).pop();
|
||||
// AppToast.showErrorToast(message: result, localContext: context);
|
||||
// startSMSService(tempType, context);
|
||||
// }),
|
||||
//
|
||||
// // projectViewModel.analytics.loginRegistration.login_fail(error: result),
|
||||
// // projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result)
|
||||
// }
|
||||
// })
|
||||
// .catchError((err) {
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// Future.delayed(Duration(seconds: 1), () {
|
||||
// print(err);
|
||||
// AppToast.showErrorToast(message: err);
|
||||
// // startSMSService(tempType);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var tempType;
|
||||
//
|
||||
// startSMSService(type, context) {
|
||||
// tempType = type;
|
||||
// late SMSOTP smsOtp; // Declare the variable first
|
||||
//
|
||||
// smsOtp = SMSOTP(
|
||||
// context,
|
||||
// type,
|
||||
// phoneNumber,
|
||||
// (code) {
|
||||
// smsOtp.dispose(); // Now we can reference it
|
||||
// checkActivationCode(value: code, context: context);
|
||||
// },
|
||||
// () {
|
||||
// smsOtp.dispose(); // Now we can reference it
|
||||
// Navigator.pop(context);
|
||||
// },
|
||||
// );
|
||||
// smsOtp.displayDialog(context);
|
||||
// }
|
||||
//
|
||||
// setDefault(context) async {
|
||||
// // showLoader(true);
|
||||
// if (await sharedPref.getObject(IMEI_USER_DATA) != null) userData = SelectDeviceIMEIRES.fromJson(await sharedPref.getObject(IMEI_USER_DATA));
|
||||
//
|
||||
// if (await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN) != null) {
|
||||
// isMoreOption = true;
|
||||
// registerd_data = await CheckPatientAuthenticationReq.fromJson(await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN));
|
||||
// }
|
||||
//
|
||||
// mobileNumber = registerd_data != null ? registerd_data.patientMobileNumber : int.parse(userData.mobile!);
|
||||
// zipCode = registerd_data != null
|
||||
// ? registerd_data.zipCode
|
||||
// : userData.outSA == true
|
||||
// ? "971"
|
||||
// : "966";
|
||||
// patientOutSA = registerd_data != null
|
||||
// ? registerd_data.zipCode == "966"
|
||||
// ? 0
|
||||
// : 1
|
||||
// : userData.outSA;
|
||||
// if (registerd_data != null) {
|
||||
// loginTokenID = await sharedPref.getString(LOGIN_TOKEN_ID);
|
||||
// loginType = registerd_data.searchType;
|
||||
// }
|
||||
// var nhic = await sharedPref.getObject(NHIC_DATA);
|
||||
// if (nhic != null) {
|
||||
// final DateFormat dateFormat = DateFormat('MM/dd/yyyy');
|
||||
// final DateFormat dateFormat2 = DateFormat('dd/MM/yyyy');
|
||||
// dob = nhic['IsHijri'] ? nhic['DateOfBirth'] : dateFormat2.format(dateFormat.parse(nhic['DateOfBirth']));
|
||||
//
|
||||
// isHijri = nhic['IsHijri'] ? 1 : 0;
|
||||
// healthId = nhic['HealthId'];
|
||||
// }
|
||||
// deviceToken = await sharedPref.getString(PUSH_TOKEN);
|
||||
// lastLogin = await sharedPref.getInt(LAST_LOGIN) != null
|
||||
// ? await sharedPref.getInt(LAST_LOGIN)
|
||||
// : userData != null
|
||||
// ? userData!.logInType
|
||||
// : null;
|
||||
//
|
||||
// // showLoader(false);
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// //cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN);
|
||||
// }
|
||||
//
|
||||
// getCommonRequest({type}) {
|
||||
// bool fileNo = false;
|
||||
// if (nationIdController.text != null && nationIdController.text.isNotEmpty) {
|
||||
// fileNo = nationIdController.text.length < 10;
|
||||
// }
|
||||
//
|
||||
// var request = SendActivationRequest();
|
||||
// request.patientMobileNumber = int.parse(phoneNumber!);
|
||||
// request.mobileNo = '0' + phoneNumber.toString();
|
||||
// request.deviceToken = deviceToken;
|
||||
// request.projectOutSA = patientOutSA == true ? true : false;
|
||||
// request.loginType = type == 1 ? type : 2;
|
||||
// request.oTPSendType = type == 1 ? type : 2; //selectedOption == 1 ? 1 : 2;
|
||||
// request.zipCode = selectedCountry.countryCode;
|
||||
//
|
||||
// request.logInTokenID = loginTokenID ?? "";
|
||||
//
|
||||
// if (registerd_data != null) {
|
||||
// request.searchType = registerd_data.searchType != null ? registerd_data.searchType : 1;
|
||||
// request.patientID = registerd_data.patientID != null ? registerd_data.patientID : 0;
|
||||
// request.patientIdentificationID = request.nationalID = registerd_data.patientIdentificationID != null ? registerd_data.patientIdentificationID : '0';
|
||||
// request.dob = registerd_data.dob;
|
||||
// request.isRegister = registerd_data.isRegister;
|
||||
// } else {
|
||||
// // request.searchType = request.searchType != null ? request.searchType : 1;
|
||||
// if (fileNo) {
|
||||
// request.patientID = userData != null && userData!.patientID != null ? userData!.patientID : int.parse(nationIdController.text);
|
||||
// request.patientIdentificationID = request.nationalID = "";
|
||||
// request.searchType = 2;
|
||||
// } else {
|
||||
// request.patientID = 0;
|
||||
// request.searchType = 1;
|
||||
// request.patientIdentificationID = request.nationalID = nationIdController != null ? nationIdController.text : '0';
|
||||
// }
|
||||
// request.isRegister = false;
|
||||
// }
|
||||
// request.deviceTypeID = request.searchType;
|
||||
// return request;
|
||||
// }
|
||||
//
|
||||
// insertIMEI() {
|
||||
// authService.insertDeviceImei(selectedOption).then((value) => {}).catchError((err) {
|
||||
// print(err);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// void checkIfIsInPatient(context) {
|
||||
// final service = ClinicListService();
|
||||
// service.checkIfInPatientAPI(context).then((res) {
|
||||
// if (res['MessageStatus'] != 1) return;
|
||||
//
|
||||
// final isAdmitted = res['isAdmitted'] == true;
|
||||
// final hasAdmissionRequest = res['hasAdmissionRequests'] == true;
|
||||
//
|
||||
// print("IS ADMITTED: $isAdmitted");
|
||||
// print("Has Admission Request: $hasAdmissionRequest");
|
||||
//
|
||||
// if (isAdmitted && res['PatientAdmittedInformation']?.isNotEmpty == true) {
|
||||
// final info = GetAdmissionInfoResponseModel.fromJson(res['PatientAdmittedInformation'][0]);
|
||||
// projectViewModel.setInPatientProjectID(res['PatientAdmittedInformation'][0]['ProjectID']);
|
||||
// projectViewModel.setInPatientAdmissionInfo(info);
|
||||
// projectViewModel.setIsPatientAdmitted(true);
|
||||
// }
|
||||
//
|
||||
// if (hasAdmissionRequest && res['MedicalInstruction']?.isNotEmpty == true) {
|
||||
// final reqInfo = GetAdmissionRequestInfoResponseModel.fromJson(res['MedicalInstruction'][0]);
|
||||
// projectViewModel.setInPatientProjectID(res['MedicalInstruction'][0]['projectId']);
|
||||
// projectViewModel.setInPatientAdmissionRequest(reqInfo);
|
||||
// projectViewModel.setPatientHasAdmissionRequest(true);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// Future<void> goToHome(context) async {
|
||||
// authenticatedUserObject.isLogin = true;
|
||||
// appointmentRateViewModel.isLogin = true;
|
||||
// projectViewModel.isLogin = true;
|
||||
// projectViewModel.user = authenticatedUserObject.user;
|
||||
// await authenticatedUserObject.getUser(getUser: true);
|
||||
//
|
||||
// getToDoCount(context);
|
||||
// checkIfIsInPatient(context);
|
||||
//
|
||||
// appointmentRateViewModel.getIsLastAppointmentRatedList(projectViewModel.isArabic ? 1 : 2).then((_) {
|
||||
// GifLoaderDialogUtils.hideDialog(AppGlobal.context);
|
||||
//
|
||||
// if (appointmentRateViewModel.isHaveAppointmentNotRate) {
|
||||
// Navigator.pushAndRemoveUntil(
|
||||
// context,
|
||||
// FadePage(page: RateAppointmentDoctor()),
|
||||
// (route) => false,
|
||||
// );
|
||||
// } else {
|
||||
// Navigator.pushAndRemoveUntil(
|
||||
// context,
|
||||
// FadePage(page: LandingPage()),
|
||||
// (route) => false,
|
||||
// );
|
||||
// }
|
||||
// insertIMEI();
|
||||
// }).catchError((error) {
|
||||
// print(error);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// void getToDoCount(context) {
|
||||
// toDoProvider.setState(0, 0, true, "0");
|
||||
// ClinicListService().getActiveAppointmentNo(context).then((res) {
|
||||
// if (res['MessageStatus'] == 1) {
|
||||
// toDoProvider.setState(
|
||||
// res['AppointmentActiveNumber'],
|
||||
// res['AncillaryOrderListCount'],
|
||||
// true,
|
||||
// "0",
|
||||
// );
|
||||
// }
|
||||
// }).catchError((err) => print(err));
|
||||
// }
|
||||
//
|
||||
// checkIfUserAgreedBefore(CheckActivationCode result, context) {
|
||||
// if (projectViewModel.havePrivilege(109)) {
|
||||
// authService.checkIfUserAgreed().then((result) {
|
||||
// if (result['IsPatientAlreadyAgreed']) {
|
||||
// goToHome(context);
|
||||
// } else {
|
||||
// authService.getUserAgreementContent().then((result) {
|
||||
// GifLoaderDialogUtils.hideDialog(AppGlobal.context);
|
||||
// Navigator.pushAndRemoveUntil(
|
||||
// context,
|
||||
// FadePage(
|
||||
// page: UserLoginAgreementPage(
|
||||
// userAgreementText: result['UserAgreementContent'],
|
||||
// authenticatedUserObject: authenticatedUserObject,
|
||||
// appointmentRateViewModel: appointmentRateViewModel,
|
||||
// selectedOption: selectedOption,
|
||||
// isArabic: projectViewModel.isArabic,
|
||||
// ),
|
||||
// ),
|
||||
// (r) => false);
|
||||
// }).catchError((err) {
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// print(err);
|
||||
// });
|
||||
// }
|
||||
// }).catchError((err) {
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// print(err);
|
||||
// });
|
||||
// } else {
|
||||
// goToHome(context);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// void dispose() {
|
||||
// nationIdController.dispose();
|
||||
// phoneController?.dispose();
|
||||
// super.dispose();
|
||||
// }
|
||||
}
|
||||
Loading…
Reference in New Issue