Add enum to verification_methods

auth_refactor
Elham Rababah 5 years ago
parent 53791f1028
commit a3caf023e2

@ -0,0 +1,24 @@
enum AuthMethodTypes { SMS, WhatsApp, Fingerprint,FaceID,MoreOptions }
extension SelectedAuthMethodTypesService on AuthMethodTypes {
// ignore: missing_return
int getTypeIdService() {
switch (this) {
case AuthMethodTypes.SMS:
return 1;
break;
case AuthMethodTypes.WhatsApp:
return 2;
break;
case AuthMethodTypes.Fingerprint:
return 3;
break;
case AuthMethodTypes.FaceID:
return 4;
break;
case AuthMethodTypes.MoreOptions:
return 5;
break;
}
}
}

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
@ -9,7 +10,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class SMSOTP {
final type;
final AuthMethodTypes type;
final mobileNo;
final Function onSuccess;
final Function onFailure;
@ -81,7 +82,7 @@ class SMSOTP {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
type == 1
type == AuthMethodTypes.SMS
? Padding(
child: Icon(
DoctorApp.verify_sms_1,

@ -1,6 +1,7 @@
import 'dart:io' show Platform;
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/core/enum/auth_method_types.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/viewModel/authentication_view_model.dart';
@ -14,7 +15,7 @@ import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
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/auth/sms-popup.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/loader/gif_loader_dialog_utils.dart';
@ -57,15 +58,16 @@ class _VerificationMethodsState extends State<VerificationMethods> {
final LocalAuthentication auth = LocalAuthentication();
var _availableBiometrics;
ProjectViewModel projectsProvider;
var isMoreOption = false;
var onlySMSBox = false;
bool isMoreOption = false;
bool onlySMSBox = false;
var loginTokenID;
DoctorProfileViewModel doctorProfileViewModel;
bool authenticated;
var fingrePrintBefore;
AuthMethodTypes fingrePrintBefore;
var selectedOption;
AuthMethodTypes selectedOption;
@override
void initState() {
@ -97,7 +99,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
@override
Widget build(BuildContext context) {
DoctorProfileViewModel authProv = Provider.of<DoctorProfileViewModel>(context);
doctorProfileViewModel = Provider.of<DoctorProfileViewModel>(context);
projectsProvider = Provider.of<ProjectViewModel>(context);
return FutureBuilder(
future: Future.wait([_loggedUserFuture]),
@ -112,7 +114,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
} else {
return SingleChildScrollView(
child: Container(
height: SizeConfig.realScreenHeight * .9,
height: SizeConfig.realScreenHeight * .87,
width: SizeConfig.realScreenWidth,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -253,14 +255,16 @@ class _VerificationMethodsState extends State<VerificationMethods> {
Expanded(
child: InkWell(
onTap: () => {
authenticateUser(3,
true, authProv)
// TODO check this logic it seem it will create bug to us
authenticateUser(AuthMethodTypes.Fingerprint,
true)
},
child: getButton(
user.logInTypeID,
authProv))),
child: methodCard(
user.logInTypeID == 4 ?AuthMethodTypes.FaceID:user.logInTypeID == 2?AuthMethodTypes.WhatsApp:user.logInTypeID ==3? AuthMethodTypes.Fingerprint:AuthMethodTypes.SMS
))),
Expanded(
child: getButton(5, authProv))
child: methodCard(AuthMethodTypes.MoreOptions))
]),
])
: Column(
@ -274,11 +278,11 @@ class _VerificationMethodsState extends State<VerificationMethods> {
MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: getButton(
3, authProv)),
child: methodCard(
AuthMethodTypes.Fingerprint)),
Expanded(
child: getButton(
4, authProv))
child: methodCard(
AuthMethodTypes.FaceID))
],
)
: SizedBox(),
@ -287,9 +291,9 @@ class _VerificationMethodsState extends State<VerificationMethods> {
MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: getButton(1, authProv)),
child: methodCard(AuthMethodTypes.SMS)),
Expanded(
child: getButton(2, authProv))
child: methodCard(AuthMethodTypes.WhatsApp))
],
),
]),
@ -325,15 +329,10 @@ class _VerificationMethodsState extends State<VerificationMethods> {
}
});
}
bool hideSilentMethods() {
return verificationMethod == 4 || verificationMethod == 3 ? true : false;
}
sendActivationCodeByOtpNotificationType(
oTPSendType, DoctorProfileViewModel authProv) async {
// TODO : build enum for verfication method
if (oTPSendType == 1 || oTPSendType == 2) {
AuthMethodTypes authMethodType) async {
if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) {
GifLoaderDialogUtils.showMyDialog(context);
int projectID = await sharedPref.getInt(PROJECT_ID);
@ -343,7 +342,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
memberID: _loggedUser['List_MemberInformation'][0]['MemberID'],
zipCode: _loggedUser['ZipCode'],
mobileNumber: _loggedUser['MobileNumber'],
otpSendType: oTPSendType.toString(),
otpSendType: authMethodType.getTypeIdService().toString(),
password: widget.password);
await widget.model
.sendActivationCodeForDoctorApp(activationCodeModel);
@ -358,11 +357,11 @@ class _VerificationMethodsState extends State<VerificationMethods> {
sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["LogInTokenID"]);
sharedPref.setString(PASSWORD, widget.password);
GifLoaderDialogUtils.hideDialog(context);
this.startSMSService(oTPSendType, authProv);
this.startSMSService(authMethodType);
}
} else {
// TODO route to this page with parameters to inicate we should present 2 option
if (Platform.isAndroid && oTPSendType == 3) {
if (Platform.isAndroid && authMethodType == AuthMethodTypes.Fingerprint) {
Helpers.showErrorToast('Your device not support this feature');
} else {
}
@ -370,7 +369,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
}
sendActivationCodeVerificationScreen(
oTPSendType, DoctorProfileViewModel authProv) async {
AuthMethodTypes authMethodType) async {
GifLoaderDialogUtils.showMyDialog(context);
ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel(
iMEI: user.iMEI,
@ -378,7 +377,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
memberID: user.doctorID,
zipCode: user.outSA == true ? '971' : '966',
mobileNumber: user.mobile,
oTPSendType: oTPSendType,
oTPSendType: authMethodType ==AuthMethodTypes.FaceID?4:authMethodType ==AuthMethodTypes.Fingerprint?3:authMethodType ==AuthMethodTypes.WhatsApp?2:1,
isMobileFingerPrint: 1,
vidaAuthTokenID: user.vidaAuthTokenID,
vidaRefreshTokenID: user.vidaRefreshTokenID);
@ -395,20 +394,20 @@ class _VerificationMethodsState extends State<VerificationMethods> {
sharedPref.setString(
VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]);
sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["LogInTokenID"]);
if (oTPSendType == 1 || oTPSendType == 2) {
if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) {
GifLoaderDialogUtils.hideDialog(context);
this.startSMSService(oTPSendType, authProv);
this.startSMSService(authMethodType);
} else {
checkActivationCode(authProv);
checkActivationCode();
}
}
}
Widget getButton(flag, authProv) {
switch (flag) {
case 2:
Widget methodCard(AuthMethodTypes authMethodType) {
switch (authMethodType) {
case AuthMethodTypes.WhatsApp:
return InkWell(
onTap: () => {authenticateUser(2, true, authProv)},
onTap: () => {authenticateUser(AuthMethodTypes.WhatsApp, true)},
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
@ -442,9 +441,9 @@ class _VerificationMethodsState extends State<VerificationMethods> {
),
)));
break;
case 1:
case AuthMethodTypes.SMS:
return InkWell(
onTap: () => {authenticateUser(1, true, authProv)},
onTap: () => {authenticateUser(AuthMethodTypes.SMS, true)},
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
@ -462,11 +461,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
height: 60,
width: 60,
),
projectsProvider.isArabic
? SizedBox(
height: 20,
)
: SizedBox(
SizedBox(
height: 20,
),
AppText(
@ -478,11 +473,11 @@ class _VerificationMethodsState extends State<VerificationMethods> {
),
)));
break;
case 3:
case AuthMethodTypes.Fingerprint:
return InkWell(
onTap: () => {
if (checkIfBiometricAvailable(BiometricType.fingerprint))
{authenticateUser(3, true, authProv)}
{authenticateUser(AuthMethodTypes.Fingerprint, true)}
},
child: Container(
margin: EdgeInsets.all(10),
@ -513,11 +508,11 @@ class _VerificationMethodsState extends State<VerificationMethods> {
),
)));
break;
case 4:
case AuthMethodTypes.FaceID:
return InkWell(
onTap: () {
if (checkIfBiometricAvailable(BiometricType.face)) {
authenticateUser(4, true, authProv);
authenticateUser(AuthMethodTypes.FaceID, true);
}
},
child:
@ -622,41 +617,32 @@ class _VerificationMethodsState extends State<VerificationMethods> {
return isAvailable;
}
formatDate(date) {
return DateFormat('MMM dd, yyy, kk:mm').format(date);
}
authenticateUser(type, isActive, authProv) {
//GifLoaderDialogUtils.showMyDialog(context);
if (type == 3 || type == 4) {
fingrePrintBefore = type;
authenticateUser( AuthMethodTypes authMethodType, isActive) {
if (authMethodType == AuthMethodTypes.Fingerprint || authMethodType == AuthMethodTypes.FaceID) {
fingrePrintBefore = authMethodType;
}
this.selectedOption = fingrePrintBefore != null ? fingrePrintBefore : type;
this.selectedOption = fingrePrintBefore != null ? fingrePrintBefore : authMethodType;
switch (type) {
case 1:
this.loginWithSMS(1, isActive, authProv);
switch (authMethodType) {
case AuthMethodTypes.SMS:
sendActivationCode(authMethodType);
break;
case 2:
this.loginWithSMS(2, isActive, authProv);
case AuthMethodTypes.WhatsApp:
sendActivationCode(authMethodType);
break;
case 3:
this.loginWithFingurePrintFace(3, isActive, authProv);
case AuthMethodTypes.Fingerprint:
this.loginWithFingerPrintOrFaceID(AuthMethodTypes.Fingerprint, isActive);
break;
case 4:
this.loginWithFingurePrintFace(4, isActive, authProv);
case AuthMethodTypes.FaceID:
this.loginWithFingerPrintOrFaceID(AuthMethodTypes.FaceID, isActive);
break;
default:
break;
}
sharedPref.setInt(OTP_TYPE, selectedOption);
// sharedPref.setInt(LAST_LOGIN),
sharedPref.setInt(OTP_TYPE, selectedOption.getTypeIdService());
}
loginWithSMS(type, isActive, authProv) {
this.sendActivationCode(type, authProv);
}
Future<void> _getAvailableBiometrics() async {
var availableBiometrics;
@ -672,15 +658,15 @@ class _VerificationMethodsState extends State<VerificationMethods> {
});
}
sendActivationCode(type, authProv) async {
sendActivationCode(AuthMethodTypes authMethodType) async {
if (user != null) {
sendActivationCodeVerificationScreen(type, authProv);
sendActivationCodeVerificationScreen(authMethodType);
} else {
sendActivationCodeByOtpNotificationType(type, authProv);
sendActivationCodeByOtpNotificationType(authMethodType);
}
}
startSMSService(type, authProv) {
startSMSService(AuthMethodTypes type) {
new SMSOTP(
context,
type,
@ -694,7 +680,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
);
});
this.checkActivationCode(authProv, value: value);
this.checkActivationCode(value: value);
},
() => {
widget.changeLoadingState(false),
@ -703,10 +689,8 @@ class _VerificationMethodsState extends State<VerificationMethods> {
).displayDialog(context);
}
loginWithFingurePrintFace(type, isActive, authProv) async {
loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async {
if (isActive) {
// this.startBiometricLoginIfAvailable();
const iosStrings = const IOSAuthMessages(
cancelButton: 'cancel',
goToSettingsButton: 'settings',
@ -724,8 +708,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
}
if (!mounted) return;
if (user != null && (user.logInTypeID == 3 || user.logInTypeID == 4)) {
this.sendActivationCode(type, authProv);
// this.checkActivationCode(authProv);
this.sendActivationCode(authMethodTypes);
} else {
setState(() {
this.onlySMSBox = true;
@ -734,7 +717,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
}
}
checkActivationCode(DoctorProfileViewModel authProv, {value}) async {
checkActivationCode( {value}) async {
CheckActivationCodeRequestModel checkActivationCodeForDoctorApp =
new CheckActivationCodeRequestModel(
zipCode:
@ -756,44 +739,20 @@ class _VerificationMethodsState extends State<VerificationMethods> {
} else {
sharedPref.setString(TOKEN, widget.model.checkActivationCodeForDoctorAppRes['AuthenticationTokenID']);
if (widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != null) {
loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0], authProv);
loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]);
sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']);
} else {
sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']);
ClinicModel clinic =
ClinicModel.fromJson(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]);
getDocProfiles(clinic, authProv);
getDocProfiles(clinic);
}
}
// 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) {
var doctor = DoctorProfileModel.fromJson(profile);
authProv.setDoctorProfile(doctor);
doctorProfileViewModel.setDoctorProfile(doctor);
sharedPref.setObj(DOCTOR_PROFILE, profile);
projectsProvider.isLogin = true;
@ -805,7 +764,7 @@ class _VerificationMethodsState extends State<VerificationMethods> {
(r) => false);
}
getDocProfiles(ClinicModel clinicInfo, authProv) {
getDocProfiles(ClinicModel clinicInfo) {
ProfileReqModel docInfo = new ProfileReqModel(
doctorID: clinicInfo.doctorID,
clinicID: clinicInfo.clinicID,
@ -813,15 +772,14 @@ class _VerificationMethodsState extends State<VerificationMethods> {
projectID: clinicInfo.projectID,
tokenID: '',
languageID: 2);
authProv.getDocProfiles(docInfo.toJson()).then((res) {
doctorProfileViewModel.getDocProfiles(docInfo.toJson()).then((res) {
if (res['MessageStatus'] == 1) {
loginProcessCompleted(res['DoctorProfileList'][0], authProv);
loginProcessCompleted(res['DoctorProfileList'][0]);
} else {
// changeLoadingState(false);
Helpers.showErrorToast(res['ErrorEndUserMessage']);
}
}).catchError((err) {
// changeLoadingState(false);
Helpers.showErrorToast(err);
});
}

Loading…
Cancel
Save