|
|
|
@ -1,24 +1,35 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/core/app_export.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/core/cache_consts.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/enums.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/enums.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/request_utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/request_utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart';
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart';
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_patient_authentication_request_model.dart';
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_patient_authentication_request_model.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_activation_code_resp_model.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/presentation/authentication/login.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/services/cache_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/dialog_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/dialog_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/services/navigation_service.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
AuthenticationRepo authenticationRepo;
|
|
|
|
AuthenticationRepo authenticationRepo;
|
|
|
|
AppState appState;
|
|
|
|
AppState appState;
|
|
|
|
ErrorHandlerService errorHandlerService;
|
|
|
|
ErrorHandlerService errorHandlerService;
|
|
|
|
DialogService dialogService;
|
|
|
|
DialogService dialogService;
|
|
|
|
|
|
|
|
NavigationService navigationService;
|
|
|
|
|
|
|
|
CacheService cacheService;
|
|
|
|
|
|
|
|
|
|
|
|
AuthenticationViewModel({
|
|
|
|
AuthenticationViewModel({
|
|
|
|
required this.appState,
|
|
|
|
required this.appState,
|
|
|
|
required this.authenticationRepo,
|
|
|
|
required this.authenticationRepo,
|
|
|
|
required this.errorHandlerService,
|
|
|
|
required this.errorHandlerService,
|
|
|
|
required this.dialogService,
|
|
|
|
required this.dialogService,
|
|
|
|
|
|
|
|
required this.navigationService,
|
|
|
|
|
|
|
|
required this.cacheService,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
final TextEditingController nationalIdController = TextEditingController();
|
|
|
|
final TextEditingController nationalIdController = TextEditingController();
|
|
|
|
@ -26,29 +37,96 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
|
|
void login() {
|
|
|
|
void login() {
|
|
|
|
if (ValidationUtils.isValidatePhoneAndId(nationalId: nationalIdController.text, phoneNumber: phoneNumberController.text)) {
|
|
|
|
if (ValidationUtils.isValidatePhoneAndId(nationalId: nationalIdController.text, phoneNumber: phoneNumberController.text)) {
|
|
|
|
} else {
|
|
|
|
} else {}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> selectDeviceImei({Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
//checkUserAuthentication();
|
|
|
|
String firebaseToken = "dOGRRszQQMGe_9wA5Hx3kO:APA91bFV5IcIJXvcCXXk0tc2ddtZgWwCPq7sGSuPr-YW7iiJpQZKgFGN9GAzCVOWL8MfheaP1slE8MdxB7lczdPBGdONQ7WbMmhgHcsUCUktq-hsapGXXqc";
|
|
|
|
bool isDubai = false;
|
|
|
|
|
|
|
|
bool authenticated = false;
|
|
|
|
|
|
|
|
late int mobileNumber;
|
|
|
|
|
|
|
|
String errorMsg = '';
|
|
|
|
|
|
|
|
var registerd_data;
|
|
|
|
|
|
|
|
bool isMoreOption = false;
|
|
|
|
|
|
|
|
var zipCode;
|
|
|
|
|
|
|
|
var patientOutSA;
|
|
|
|
|
|
|
|
var loginTokenID;
|
|
|
|
|
|
|
|
var loginType;
|
|
|
|
|
|
|
|
var deviceToken;
|
|
|
|
|
|
|
|
var lastLogin;
|
|
|
|
|
|
|
|
final FocusNode myFocusNode = FocusNode();
|
|
|
|
|
|
|
|
late int selectedOption = 1;
|
|
|
|
|
|
|
|
bool onlySMSBox = false;
|
|
|
|
|
|
|
|
int fingrePrintBefore = 0;
|
|
|
|
|
|
|
|
var dob;
|
|
|
|
|
|
|
|
late int isHijri;
|
|
|
|
|
|
|
|
var healthId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> selectDeviceImei({required Function(dynamic data) onSuccess, Function(String)? onError}) async {
|
|
|
|
|
|
|
|
String firebaseToken = appState.deviceToken == ""
|
|
|
|
|
|
|
|
? "dOGRRszQQMGe_9wA5Hx3kO:APA91bFV5IcIJXvcCXXk0tc2ddtZgWwCPq7sGSuPr-YW7iiJpQZKgFGN9GAzCVOWL8MfheaP1slE8MdxB7lczdPBGdONQ7WbMmhgHcsUCUktq-hsapGXXqc"
|
|
|
|
|
|
|
|
: appState.deviceToken;
|
|
|
|
final result = await authenticationRepo.selectDeviceByImei(firebaseToken: firebaseToken);
|
|
|
|
final result = await authenticationRepo.selectDeviceByImei(firebaseToken: firebaseToken);
|
|
|
|
|
|
|
|
|
|
|
|
result.fold(
|
|
|
|
result.fold(
|
|
|
|
(failure) async => await errorHandlerService.handleError(failure: failure),
|
|
|
|
(failure) async => await errorHandlerService.handleError(failure: failure),
|
|
|
|
(apiResponse) {
|
|
|
|
(apiResponse) {
|
|
|
|
if (apiResponse.messageStatus == 2) {
|
|
|
|
if (apiResponse.messageStatus == 1) {
|
|
|
|
//TODO: NEXT CREATION
|
|
|
|
onSuccess(apiResponse.data);
|
|
|
|
dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
|
|
} else if (apiResponse.messageStatus == 2) {
|
|
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
|
|
dialogService.showErrorDialog(message: "Message Status = 2", onOkPressed: () {});
|
|
|
|
//todo: move to next api call
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> checkUserAuthentication({OTPTypeEnum otpTypeEnum, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
Future<void> onLoginPressed() async {
|
|
|
|
|
|
|
|
var data = await cacheService.getObject(key: CacheConst.imeiUserData);
|
|
|
|
|
|
|
|
//TODO: Why???
|
|
|
|
|
|
|
|
cacheService.remove(key: CacheConst.registerDataForLogin);
|
|
|
|
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
SelectDeviceByImeiRespModelElement savedData = SelectDeviceByImeiRespModelElement.fromJson(data);
|
|
|
|
|
|
|
|
// TODO : SavedLogin Page is not there or renamed.
|
|
|
|
|
|
|
|
// navigationService.pushPage(page: SavedLogin(savedData));
|
|
|
|
|
|
|
|
// Navigator.of(context).push(
|
|
|
|
|
|
|
|
// MaterialPageRoute(
|
|
|
|
|
|
|
|
// builder: (BuildContext context) => SavedLogin(savedData),
|
|
|
|
|
|
|
|
// ),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Todo: Show Loader Here
|
|
|
|
|
|
|
|
// GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectDeviceImei(
|
|
|
|
|
|
|
|
onSuccess: (dynamic respData) async {
|
|
|
|
|
|
|
|
var data = await cacheService.getObject(key: CacheConst.imeiUserData);
|
|
|
|
|
|
|
|
if (respData != null) {
|
|
|
|
|
|
|
|
cacheService.saveObject(key: CacheConst.imeiUserData, value: respData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SelectDeviceByImeiRespModelElement savedData = SelectDeviceByImeiRespModelElement.fromJson(data);
|
|
|
|
|
|
|
|
// setUserValues(value);
|
|
|
|
|
|
|
|
// TODO : SavedLogin Page is not there or renamed.
|
|
|
|
|
|
|
|
// navigationService.pushPage(page: SavedLogin(savedData));
|
|
|
|
|
|
|
|
// Navigator.of(context).push(
|
|
|
|
|
|
|
|
// MaterialPageRoute(
|
|
|
|
|
|
|
|
// builder: (BuildContext context) => SavedLogin(savedData),
|
|
|
|
|
|
|
|
// ),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//Todo: Hide Loader Here
|
|
|
|
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
|
|
|
navigationService.pushPage(page: LoginScreen());
|
|
|
|
|
|
|
|
// Navigator.of(context).push(
|
|
|
|
|
|
|
|
// MaterialPageRoute(
|
|
|
|
|
|
|
|
// builder: (BuildContext context) => WelcomeLogin(),
|
|
|
|
|
|
|
|
// ),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> checkUserAuthentication({required OTPTypeEnum otpTypeEnum, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
CheckPatientAuthenticationReq checkPatientAuthenticationReq = RequestUtils.getCommonRequestWelcome(
|
|
|
|
CheckPatientAuthenticationReq checkPatientAuthenticationReq = RequestUtils.getCommonRequestWelcome(
|
|
|
|
phoneNumber: '0567184134',
|
|
|
|
phoneNumber: '0567184134',
|
|
|
|
otpTypeEnum: OTPTypeEnum.sms,
|
|
|
|
otpTypeEnum: OTPTypeEnum.sms,
|
|
|
|
@ -60,37 +138,6 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
nationIdText: '1234567890',
|
|
|
|
nationIdText: '1234567890',
|
|
|
|
countryCode: 'SA',
|
|
|
|
countryCode: 'SA',
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// Future<void> 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) {});
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final result = await authenticationRepo.checkPatientAuthentication(checkPatientAuthenticationReq: checkPatientAuthenticationReq);
|
|
|
|
final result = await authenticationRepo.checkPatientAuthentication(checkPatientAuthenticationReq: checkPatientAuthenticationReq);
|
|
|
|
result.fold(
|
|
|
|
result.fold(
|
|
|
|
@ -104,71 +151,153 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
sendActivationCode(otpTypeEnum: otpTypeEnum);
|
|
|
|
sendActivationCode(otpTypeEnum: otpTypeEnum);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (apiResponse.data['IsAuthenticated']) {
|
|
|
|
if (apiResponse.data['IsAuthenticated']) {
|
|
|
|
checkActivationCode(onWrongActivationCode: (String? message) {});
|
|
|
|
checkActivationCode(onWrongActivationCode: (String? message) {}, activationCode: 0000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Future<void> sendActivationCode({required OTPTypeEnum otpTypeEnum}) async {
|
|
|
|
Future<void> sendActivationCode({
|
|
|
|
// var request = RequestUtils.getCommonRequestAuthProvider(
|
|
|
|
required OTPTypeEnum otpTypeEnum,
|
|
|
|
// otpTypeEnum: otpTypeEnum,
|
|
|
|
}) async {
|
|
|
|
// registeredData: null,
|
|
|
|
var request = RequestUtils.getCommonRequestAuthProvider(
|
|
|
|
// deviceToken: "dummyLoginToken456",
|
|
|
|
otpTypeEnum: otpTypeEnum,
|
|
|
|
// mobileNumber: "0567184134",
|
|
|
|
registeredData: null,
|
|
|
|
// zipCode: "SA",
|
|
|
|
deviceToken: "dummyLoginToken456",
|
|
|
|
// patientOutSA: true,
|
|
|
|
mobileNumber: "0567184134",
|
|
|
|
// loginTokenID: "dummyLoginToken456",
|
|
|
|
zipCode: "SA",
|
|
|
|
// selectedOption: selectedOption,
|
|
|
|
patientOutSA: true,
|
|
|
|
// patientId: 12345,
|
|
|
|
loginTokenID: "dummyLoginToken456",
|
|
|
|
// );
|
|
|
|
selectedOption: otpTypeEnum.toInt(),
|
|
|
|
//
|
|
|
|
patientId: 12345,
|
|
|
|
// request.sMSSignature = await SMSOTP.getSignature();
|
|
|
|
);
|
|
|
|
// selectedOption = type;
|
|
|
|
|
|
|
|
// // GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
// TODO: GET APP SMS SIGNATURE HERE
|
|
|
|
// if (healthId != null || isDubai) {
|
|
|
|
request.sMSSignature = "";
|
|
|
|
// if (!isDubai) {
|
|
|
|
// GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
// request.dob = dob; //isHijri == 1 ? dob : dateFormat2.format(dateFormat.parse(dob));
|
|
|
|
|
|
|
|
// }
|
|
|
|
bool isForRegister = healthId != null || isDubai;
|
|
|
|
// request.healthId = healthId;
|
|
|
|
if (isForRegister) {
|
|
|
|
// request.isHijri = isHijri;
|
|
|
|
if (!isDubai) {
|
|
|
|
// await this.apiClient.sendActivationCodeRegister(request).then((result) {
|
|
|
|
request.dob = dob; //isHijri == 1 ? dob : dateFormat2.format(dateFormat.parse(dob));
|
|
|
|
// // GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
}
|
|
|
|
// if (result != null && result['isSMSSent'] == true) {
|
|
|
|
request.healthId = healthId;
|
|
|
|
// this.startSMSService(type);
|
|
|
|
request.isHijri = isHijri;
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
// }).catchError((r) {
|
|
|
|
request.dob = "";
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
request.healthId = "";
|
|
|
|
// context.showBottomSheet(
|
|
|
|
request.isHijri = 0;
|
|
|
|
// child: ExceptionBottomSheet(
|
|
|
|
}
|
|
|
|
// message: r.toString(),
|
|
|
|
|
|
|
|
// onOkPressed: () {
|
|
|
|
final resultEither = await authenticationRepo.sendActivationCodeRepo(
|
|
|
|
// Navigator.of(context).pop();
|
|
|
|
checkPatientAuthenticationReq: request,
|
|
|
|
// },
|
|
|
|
isRegister: isForRegister,
|
|
|
|
// ));
|
|
|
|
languageID: 'er',
|
|
|
|
// // AppToast.showErrorToast(message: r);
|
|
|
|
);
|
|
|
|
// });
|
|
|
|
resultEither.fold(
|
|
|
|
// } else {
|
|
|
|
(failure) async => await errorHandlerService.handleError(failure: failure),
|
|
|
|
// request.dob = "";
|
|
|
|
(apiResponse) {
|
|
|
|
// request.healthId = "";
|
|
|
|
if (apiResponse.data != null && apiResponse.data['isSMSSent'] == true) {
|
|
|
|
// request.isHijri = 0;
|
|
|
|
// startSMSService(otpTypeEnum.toInt());
|
|
|
|
// await this.authService.sendActivationCode(request).then((result) {
|
|
|
|
navigateToOTPScreen(otpTypeEnum: otpTypeEnum, phoneNumber: request.mobileNumber);
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
}
|
|
|
|
// if (result != null && result['isSMSSent'] == true) {
|
|
|
|
},
|
|
|
|
// this.startSMSService(type);
|
|
|
|
);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }).catchError((r) {
|
|
|
|
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
Future<void> checkActivationCode({
|
|
|
|
// context.showBottomSheet(
|
|
|
|
required int activationCode,
|
|
|
|
// child: ExceptionBottomSheet(
|
|
|
|
required Function(String? message) onWrongActivationCode,
|
|
|
|
// message: r.toString(),
|
|
|
|
}) async {
|
|
|
|
// onOkPressed: () {
|
|
|
|
final request = RequestUtils.getCommonRequestWelcome(
|
|
|
|
// Navigator.of(context).pop();
|
|
|
|
phoneNumber: '0567184134',
|
|
|
|
// },
|
|
|
|
otpTypeEnum: OTPTypeEnum.sms,
|
|
|
|
// ));
|
|
|
|
deviceToken: 'dummyDeviceToken123',
|
|
|
|
// // AppToast.showErrorToast(message: r.toString());
|
|
|
|
patientOutSA: true,
|
|
|
|
// });
|
|
|
|
loginTokenID: 'dummyLoginToken456',
|
|
|
|
// }
|
|
|
|
registeredData: null,
|
|
|
|
// }
|
|
|
|
patientId: 12345,
|
|
|
|
|
|
|
|
nationIdText: '1234567890',
|
|
|
|
|
|
|
|
countryCode: 'SA',
|
|
|
|
|
|
|
|
).toJson();
|
|
|
|
|
|
|
|
dynamic res;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isForRegister = healthId != null || isDubai;
|
|
|
|
|
|
|
|
if (isForRegister) {
|
|
|
|
|
|
|
|
if (isDubai) request['DOB'] = dob;
|
|
|
|
|
|
|
|
request['HealthId'] = healthId;
|
|
|
|
|
|
|
|
request['IsHijri'] = isHijri;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final resultEither = await authenticationRepo.checkActivationCodeRepo(
|
|
|
|
|
|
|
|
newRequest: request,
|
|
|
|
|
|
|
|
activationCode: activationCode.toString(),
|
|
|
|
|
|
|
|
isRegister: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
res = resultEither;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resultEither.fold((failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) {
|
|
|
|
|
|
|
|
final activation = CheckActivationCode.fromJson(apiResponse.data as Map<String, dynamic>);
|
|
|
|
|
|
|
|
if (registerd_data?.isRegister == true) {
|
|
|
|
|
|
|
|
navigationService.popUntilNamed(AppRoutes.registerNewScreen);
|
|
|
|
|
|
|
|
// Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
final resultEither = await authenticationRepo.checkActivationCodeRepo(
|
|
|
|
|
|
|
|
newRequest: request,
|
|
|
|
|
|
|
|
activationCode: activationCode.toString(),
|
|
|
|
|
|
|
|
isRegister: false,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
res = resultEither;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resultEither.fold((failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) {
|
|
|
|
|
|
|
|
final activation = CheckActivationCode.fromJson(resultEither as Map<String, dynamic>);
|
|
|
|
|
|
|
|
if (activation.errorCode == '699') {
|
|
|
|
|
|
|
|
// Todo: Hide Loader
|
|
|
|
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
|
|
|
onWrongActivationCode(activation.errorEndUserMessage);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (registerd_data?.isRegister == true) {
|
|
|
|
|
|
|
|
navigationService.popUntilNamed(AppRoutes.registerNewScreen);
|
|
|
|
|
|
|
|
// Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// TODO: setPreferences and stuff
|
|
|
|
|
|
|
|
// sharedPref.remove(FAMILY_FILE);
|
|
|
|
|
|
|
|
// activation.list!.isFamily = false;
|
|
|
|
|
|
|
|
// userData = activation.list;
|
|
|
|
|
|
|
|
// sharedPref.setString(BLOOD_TYPE, activation.patientBloodType ?? "");
|
|
|
|
|
|
|
|
// authenticatedUserObject.user = activation.list!;
|
|
|
|
|
|
|
|
// projectViewModel.setPrivilege(privilegeList: res);
|
|
|
|
|
|
|
|
// await sharedPref.setObject(MAIN_USER, activation.list);
|
|
|
|
|
|
|
|
// await sharedPref.setObject(USER_PROFILE, activation.list);
|
|
|
|
|
|
|
|
// loginTokenID = activation.logInTokenID;
|
|
|
|
|
|
|
|
// await sharedPref.setObject(LOGIN_TOKEN_ID, activation.logInTokenID);
|
|
|
|
|
|
|
|
// await sharedPref.setString(TOKEN, activation.authenticationTokenID!);
|
|
|
|
|
|
|
|
// checkIfUserAgreedBefore(activation);
|
|
|
|
|
|
|
|
// projectViewModel.analytics.loginRegistration.login_successful();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> navigateToOTPScreen({required OTPTypeEnum otpTypeEnum, required String phoneNumber}) async {
|
|
|
|
|
|
|
|
navigationService.pushToOtpScreen(
|
|
|
|
|
|
|
|
phoneNumber: phoneNumber,
|
|
|
|
|
|
|
|
checkActivationCode: (int activationCode) async {
|
|
|
|
|
|
|
|
await checkActivationCode(
|
|
|
|
|
|
|
|
activationCode: activationCode,
|
|
|
|
|
|
|
|
onWrongActivationCode: (String? value) {
|
|
|
|
|
|
|
|
onWrongActivationCode(message: value);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onResendOTPPressed: (String phoneNumber) {},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> onWrongActivationCode({String? message}) async {
|
|
|
|
|
|
|
|
// TODO: HANDLE THIS VIA BOTTOM SHEET
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|