refactor verification methods services

auth_refactor
Elham Rababah 5 years ago
parent b20d936933
commit 9f1f06f2fc

@ -1,13 +1,30 @@
import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart';
import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart';
import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart';
import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart';
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:provider/provider.dart';
class AuthService extends BaseService { class AuthService extends BaseService {
List<GetIMEIDetailsModel> _imeiDetails = []; List<GetIMEIDetailsModel> _imeiDetails = [];
List<GetIMEIDetailsModel> get dashboardItemsList => _imeiDetails; List<GetIMEIDetailsModel> get dashboardItemsList => _imeiDetails;
//TODO Change this to models
Map<String, dynamic> _loginInfo = {}; Map<String, dynamic> _loginInfo = {};
Map<String, dynamic> get loginInfo => _loginInfo; Map<String, dynamic> get loginInfo => _loginInfo;
Map<String, dynamic> _activationCodeVerificationScreenRes = {};
Map<String, dynamic> get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes;
Map<String, dynamic> _activationCodeForDoctorAppRes = {};
Map<String, dynamic> get activationCodeForDoctorAppRes => _activationCodeForDoctorAppRes;
Map<String, dynamic> _checkActivationCodeForDoctorAppRes = {};
Map<String, dynamic> get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes;
Future selectDeviceImei(imei) async { Future selectDeviceImei(imei) async {
try { try {
// dynamic localRes; // dynamic localRes;
@ -45,4 +62,65 @@ class AuthService extends BaseService {
} }
} }
Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async {
hasError = false;
_activationCodeVerificationScreenRes = {};
try {
await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_VERIFICATION_SCREEN,
onSuccess: (dynamic response, int statusCode) {
_activationCodeVerificationScreenRes = response;
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, body: activationCodeModel.toJson());
} catch (error) {
hasError = true;
super.error = error;
}
}
Future sendActivationCodeForDoctorApp(ActivationCodeModel activationCodeModel)async {
hasError = false;
_activationCodeForDoctorAppRes = {};
try {
await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_DOCTOR_APP,
onSuccess: (dynamic response, int statusCode) {
_activationCodeForDoctorAppRes = response;
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, body: activationCodeModel.toJson());
} catch (error) {
hasError = true;
super.error = error;
}
}
Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel)async {
hasError = false;
_checkActivationCodeForDoctorAppRes = {};
try {
await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP,
onSuccess: (dynamic response, int statusCode) {
// TODO improve the logic here
Provider.of<AuthViewModel>(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear();
_checkActivationCodeForDoctorAppRes = response;
Provider.of<AuthViewModel>(AppGlobal.CONTEX, listen: false).selectedClinicName =
ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName;
response['List_DoctorsClinic'].forEach((v) {
Provider.of<AuthViewModel>(AppGlobal.CONTEX, listen: false).doctorsClinicList.add(new ClinicModel.fromJson(v));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, body: checkActivationCodeRequestModel.toJson());
} catch (error) {
hasError = true;
super.error = error;
}
}
} }

@ -6,7 +6,7 @@ import 'package:doctor_app_flutter/core/model/insert_imei_model.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart';
import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart';
import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart';
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
@ -95,46 +95,6 @@ class AuthViewModel extends BaseViewModel {
} }
} }
Future sendActivationCodeForDoctorApp(
ActivationCodeModel activationCodeModel) async {
try {
var localRes;
await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_DOCTOR_APP,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
}, onFailure: (String error, int statusCode) {
throw error;
}, body: activationCodeModel.toJson());
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
Future<dynamic> checkActivationCodeForDoctorApp(
CheckActivationCodeRequestModel checkActivationCodeRequestModel) async {
try {
dynamic localRes;
await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
selectedClinicName =
ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName;
response['List_DoctorsClinic'].forEach((v) {
doctorsClinicList.add(new ClinicModel.fromJson(v));
});
}, onFailure: (String error, int statusCode) {
throw error;
}, body: checkActivationCodeRequestModel.toJson());
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
Future<dynamic> getDocProfiles(docInfo, Future<dynamic> getDocProfiles(docInfo,
{bool allowChangeProfile = true}) async { {bool allowChangeProfile = true}) async {
try { try {
@ -158,21 +118,4 @@ class AuthViewModel extends BaseViewModel {
throw error; throw error;
} }
} }
Future sendActivationCodeVerificationScreen(
ActivationCodeModel2 activationCodeModel) async {
try {
var localRes;
await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_VERIFICATION_SCREEN,
onSuccess: (dynamic response, int statusCode) {
localRes = response;
}, onFailure: (String error, int statusCode) {
throw error;
}, body: activationCodeModel.toJson());
return Future.value(localRes);
} catch (error) {
print(error);
throw error;
}
}
} }

@ -1,3 +1,4 @@
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart';
import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart';
@ -6,9 +7,14 @@ import 'package:doctor_app_flutter/core/service/auth_service.dart';
import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/locator.dart'; import 'package:doctor_app_flutter/locator.dart';
import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart';
import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart';
import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:provider/provider.dart';
import 'auth_view_model.dart';
class IMEIViewModel extends BaseViewModel { class IMEIViewModel extends BaseViewModel {
AuthService _authService = locator<AuthService>(); AuthService _authService = locator<AuthService>();
@ -17,6 +23,10 @@ class IMEIViewModel extends BaseViewModel {
List<GetIMEIDetailsModel> get imeiDetails => _authService.dashboardItemsList; List<GetIMEIDetailsModel> get imeiDetails => _authService.dashboardItemsList;
List<GetHospitalsResponseModel> get hospitals => _hospitalsService.hospitals; List<GetHospitalsResponseModel> get hospitals => _hospitalsService.hospitals;
get loginInfo => _authService.loginInfo; get loginInfo => _authService.loginInfo;
get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes;
get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes;
get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes;
Future selectDeviceImei(imei) async { Future selectDeviceImei(imei) async {
setState(ViewState.Busy); setState(ViewState.Busy);
await _authService.selectDeviceImei(imei); await _authService.selectDeviceImei(imei);
@ -37,9 +47,19 @@ class IMEIViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
Future sendActivationCodeVerificationScreen(ActivationCodeModel2 activationCodeModel) async { Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async {
setState(ViewState.BusyLocal);
await _authService.sendActivationCodeVerificationScreen(activationCodeModel);
if (_authService.hasError) {
error = _authService.error;
setState(ViewState.ErrorLocal);
} else
setState(ViewState.Idle);
}
Future sendActivationCodeForDoctorApp(ActivationCodeModel activationCodeModel) async {
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
// await _authService.sendActivationCodeVerificationScreen(userInfo); await _authService.sendActivationCodeForDoctorApp(activationCodeModel);
if (_authService.hasError) { if (_authService.hasError) {
error = _authService.error; error = _authService.error;
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
@ -47,6 +67,18 @@ class IMEIViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel) async {
setState(ViewState.BusyLocal);
await _authService.checkActivationCodeForDoctorApp(checkActivationCodeRequestModel);
if (_authService.hasError) {
error = _authService.error;
setState(ViewState.ErrorLocal);
} else {
setState(ViewState.Idle);
}
}
Future getHospitalsList(memberID) async { Future getHospitalsList(memberID) async {
GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel();

@ -1,4 +1,4 @@
class ActivationCodeModel2 { class ActivationCodeForVerificationScreenModel {
int oTPSendType; int oTPSendType;
String mobileNumber; String mobileNumber;
String zipCode; String zipCode;
@ -12,7 +12,7 @@ class ActivationCodeModel2 {
String vidaAuthTokenID; String vidaAuthTokenID;
String vidaRefreshTokenID; String vidaRefreshTokenID;
String iMEI; String iMEI;
ActivationCodeModel2( ActivationCodeForVerificationScreenModel(
{this.oTPSendType, {this.oTPSendType,
this.mobileNumber, this.mobileNumber,
this.zipCode, this.zipCode,
@ -27,7 +27,7 @@ class ActivationCodeModel2 {
this.vidaRefreshTokenID, this.vidaRefreshTokenID,
this.iMEI}); this.iMEI});
ActivationCodeModel2.fromJson(Map<String, dynamic> json) { ActivationCodeForVerificationScreenModel.fromJson(Map<String, dynamic> json) {
oTPSendType = json['OTP_SendType']; oTPSendType = json['OTP_SendType'];
mobileNumber = json['MobileNumber']; mobileNumber = json['MobileNumber'];
zipCode = json['ZipCode']; zipCode = json['ZipCode'];

@ -459,6 +459,7 @@ class _LoginsreenState extends State<Loginsreen> {
sharedPref.setInt(PROJECT_ID, userInfo.projectID); sharedPref.setInt(PROJECT_ID, userInfo.projectID);
await model.login(userInfo); await model.login(userInfo);
if (model.state == ViewState.ErrorLocal) { if (model.state == ViewState.ErrorLocal) {
GifLoaderDialogUtils.hideDialog(context);
Helpers.showErrorToast(model.error); Helpers.showErrorToast(model.error);
} else { } else {

@ -1,3 +1,5 @@
import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
@ -25,27 +27,30 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppScaffold( return BaseView<IMEIViewModel>(
isLoading: _isLoading, onModelReady: (model) async {},
isShowAppBar: false, builder: (_, model, w) => AppScaffold(
isHomeIcon: false, isLoading: _isLoading,
backgroundColor: HexColor('#F8F8F8'), isShowAppBar: false,
body: ListView(children: <Widget>[ isHomeIcon: false,
Container( backgroundColor: HexColor('#F8F8F8'),
margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), body: ListView(children: <Widget>[
child: Column( Container(
crossAxisAlignment: CrossAxisAlignment.start, margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0),
children: <Widget>[ child: Column(
SizedBox( crossAxisAlignment: CrossAxisAlignment.start,
height: 50, children: <Widget>[
), SizedBox(
VerificationMethods( height: 50,
password: widget.password, ),
changeLoadingState: changeLoadingState, VerificationMethods(
), password: widget.password,
], changeLoadingState: changeLoadingState,
), model:model
), ),
])); ],
),
),
])));
} }
} }

@ -1,11 +1,13 @@
import 'dart:io' show Platform; import 'dart:io' show Platform;
import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart';
import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart';
import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart';
import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart';
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart'; import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart';
@ -15,6 +17,7 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/otp/sms-popup.dart'; import 'package:doctor_app_flutter/widgets/otp/sms-popup.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -35,10 +38,11 @@ DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
Helpers helpers = Helpers(); Helpers helpers = Helpers();
class VerificationMethods extends StatefulWidget { class VerificationMethods extends StatefulWidget {
VerificationMethods({this.changeLoadingState, this.password}); VerificationMethods({this.changeLoadingState, this.password, this.model});
final password; final password;
final Function changeLoadingState; final Function changeLoadingState;
final IMEIViewModel model;
@override @override
_VerificationMethodsState createState() => _VerificationMethodsState(); _VerificationMethodsState createState() => _VerificationMethodsState();
@ -330,8 +334,10 @@ class _VerificationMethodsState extends State<VerificationMethods> {
oTPSendType, AuthViewModel authProv) async { oTPSendType, AuthViewModel authProv) async {
// TODO : build enum for verfication method // TODO : build enum for verfication method
if (oTPSendType == 1 || oTPSendType == 2) { if (oTPSendType == 1 || oTPSendType == 2) {
widget.changeLoadingState(true); GifLoaderDialogUtils.showMyDialog(context);
int projectID = await sharedPref.getInt(PROJECT_ID); int projectID = await sharedPref.getInt(PROJECT_ID);
// TODO create model for _loggedUser;
ActivationCodeModel activationCodeModel = ActivationCodeModel( ActivationCodeModel activationCodeModel = ActivationCodeModel(
facilityId: projectID, facilityId: projectID,
memberID: _loggedUser['List_MemberInformation'][0]['MemberID'], memberID: _loggedUser['List_MemberInformation'][0]['MemberID'],
@ -339,49 +345,34 @@ class _VerificationMethodsState extends State<VerificationMethods> {
mobileNumber: _loggedUser['MobileNumber'], mobileNumber: _loggedUser['MobileNumber'],
otpSendType: oTPSendType.toString(), otpSendType: oTPSendType.toString(),
password: widget.password); password: widget.password);
await widget.model
try { .sendActivationCodeForDoctorApp(activationCodeModel);
authProv if(widget.model.state == ViewState.ErrorLocal) {
.sendActivationCodeForDoctorApp(activationCodeModel) Helpers.showErrorToast(widget.model.error);
.then((res) { GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) { }else{
print("VerificationCode : " + res["VerificationCode"]); print("VerificationCode : " + widget.model.activationCodeForDoctorAppRes["VerificationCode"]);
sharedPref.setString(VIDA_AUTH_TOKEN_ID, res["VidaAuthTokenID"]); sharedPref.setString(VIDA_AUTH_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["VidaAuthTokenID"]);
sharedPref.setString( sharedPref.setString(
VIDA_REFRESH_TOKEN_ID, res["VidaRefreshTokenID"]); VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]);
sharedPref.setString(LOGIN_TOKEN_ID, res["LogInTokenID"]); sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["LogInTokenID"]);
sharedPref.setString(PASSWORD, widget.password); sharedPref.setString(PASSWORD, widget.password);
this.startSMSService(oTPSendType, authProv); GifLoaderDialogUtils.hideDialog(context);
} else { this.startSMSService(oTPSendType, authProv);
print(res['ErrorEndUserMessage']); }
Helpers.showErrorToast(res['ErrorEndUserMessage']);
}
}).catchError((err) {
print('$err');
widget.changeLoadingState(false);
Helpers.showErrorToast();
});
} catch (e) {}
} else { } else {
// TODO route to this page with parameters to inicate we should present 2 option // TODO route to this page with parameters to inicate we should present 2 option
if (Platform.isAndroid && oTPSendType == 3) { if (Platform.isAndroid && oTPSendType == 3) {
Helpers.showErrorToast('Your device not support this feature'); Helpers.showErrorToast('Your device not support this feature');
} else { } else {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (BuildContext context) =>
// VerificationMethodsScreen(password: widget.password,)));
// Navigator.of(context).pushNamed(VERIFICATION_METHODS,
// arguments: {'verificationMethod': oTPSendType});
} }
} }
} }
sendActivationCodeVerificationScreen( sendActivationCodeVerificationScreen(
oTPSendType, AuthViewModel authProv) async { oTPSendType, AuthViewModel authProv) async {
widget.changeLoadingState(true); GifLoaderDialogUtils.showMyDialog(context);
ActivationCodeModel2 activationCodeModel = ActivationCodeModel2( ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel(
iMEI: user.iMEI, iMEI: user.iMEI,
facilityId: user.projectID, facilityId: user.projectID,
memberID: user.doctorID, memberID: user.doctorID,
@ -392,37 +383,25 @@ class _VerificationMethodsState extends State<VerificationMethods> {
vidaAuthTokenID: user.vidaAuthTokenID, vidaAuthTokenID: user.vidaAuthTokenID,
vidaRefreshTokenID: user.vidaRefreshTokenID); vidaRefreshTokenID: user.vidaRefreshTokenID);
try { await widget.model
authProv .sendActivationCodeVerificationScreen(activationCodeModel);
.sendActivationCodeVerificationScreen(activationCodeModel)
.then((res) { if(widget.model.state == ViewState.ErrorLocal) {
if (res['MessageStatus'] == 1) { GifLoaderDialogUtils.hideDialog(context);
print("VerificationCode : " + res["VerificationCode"]); Helpers.showErrorToast(widget.model.error);
sharedPref.setString(VIDA_AUTH_TOKEN_ID, res["VidaAuthTokenID"]); } else {
sharedPref.setString( print("VerificationCode : " + widget.model.activationCodeVerificationScreenRes["VerificationCode"]);
VIDA_REFRESH_TOKEN_ID, res["VidaRefreshTokenID"]); sharedPref.setString(VIDA_AUTH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaAuthTokenID"]);
sharedPref.setString(LOGIN_TOKEN_ID, res["LogInTokenID"]); sharedPref.setString(
if (oTPSendType == 1 || oTPSendType == 2) { VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]);
widget.changeLoadingState(false); sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["LogInTokenID"]);
this.startSMSService(oTPSendType, authProv); if (oTPSendType == 1 || oTPSendType == 2) {
} else { GifLoaderDialogUtils.hideDialog(context);
checkActivationCode(authProv); this.startSMSService(oTPSendType, authProv);
}
} else { } else {
print(res['ErrorEndUserMessage']); checkActivationCode(authProv);
Helpers.showErrorToast(res['ErrorEndUserMessage']);
} }
}).catchError((err) { }
print('$err');
widget.changeLoadingState(false);
Helpers.showErrorToast();
});
} catch (e) {}
// }
// else {
// checkActivationCode(authProv);
// }
} }
Widget getButton(flag, authProv) { Widget getButton(flag, authProv) {
@ -741,7 +720,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
stickyAuth: true, stickyAuth: true,
iOSAuthStrings: iosStrings); iOSAuthStrings: iosStrings);
} on PlatformException catch (e) { } on PlatformException catch (e) {
DrAppToastMsg.showErrorToast(e); DrAppToastMsg.showErrorToast(e.toString());
} }
if (!mounted) return; if (!mounted) return;
if (user != null && (user.logInTypeID == 3 || user.logInTypeID == 4)) { if (user != null && (user.logInTypeID == 3 || user.logInTypeID == 4)) {
@ -769,30 +748,47 @@ class _VerificationMethodsState extends State<VerificationMethods> {
activationCode: value ?? '0000', activationCode: value ?? '0000',
oTPSendType: await sharedPref.getInt(OTP_TYPE), oTPSendType: await sharedPref.getInt(OTP_TYPE),
generalid: "Cs2020@2016\$2958"); generalid: "Cs2020@2016\$2958");
await widget.model.checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp);
authProv if(widget.model.state == ViewState.ErrorLocal){
.checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp) Navigator.pop(context);
.then((res) async { Helpers.showErrorToast(widget.model.error);
widget.changeLoadingState(false); } else {
if (res['MessageStatus'] == 1) { sharedPref.setString(TOKEN, widget.model.checkActivationCodeForDoctorAppRes['AuthenticationTokenID']);
sharedPref.setString(TOKEN, res['AuthenticationTokenID']); if (widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != null) {
if (res['List_DoctorProfile'] != null) { loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0], authProv);
loginProcessCompleted(res['List_DoctorProfile'][0], authProv); sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']);
sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']);
} else {
sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']);
ClinicModel clinic =
ClinicModel.fromJson(res['List_DoctorsClinic'][0]);
getDocProfiles(clinic, authProv);
}
} else { } else {
Navigator.pop(context); sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']);
Helpers.showErrorToast(res['ErrorEndUserMessage']); ClinicModel clinic =
ClinicModel.fromJson(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]);
getDocProfiles(clinic, authProv);
} }
}).catchError((err) { }
Navigator.pop(context);
Helpers.showErrorToast(err); // authProv
}); // .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp)
// .then((res) async {
// widget.changeLoadingState(false);
// if (res['MessageStatus'] == 1) {
// sharedPref.setString(TOKEN, res['AuthenticationTokenID']);
// if (res['List_DoctorProfile'] != null) {
// loginProcessCompleted(res['List_DoctorProfile'][0], authProv);
// sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']);
// } else {
// sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']);
// ClinicModel clinic =
// ClinicModel.fromJson(res['List_DoctorsClinic'][0]);
// getDocProfiles(clinic, authProv);
// }
// } else {
// Navigator.pop(context);
// Helpers.showErrorToast(res['ErrorEndUserMessage']);
// }
// }).catchError((err) {
// Navigator.pop(context);
// Helpers.showErrorToast(err);
// });
} }
loginProcessCompleted(Map<String, dynamic> profile, authProv) { loginProcessCompleted(Map<String, dynamic> profile, authProv) {

Loading…
Cancel
Save