Merge branch 'development_mirza' into 'master'

Login with face and finger fixed

See merge request mirza.shafique/mohem_flutter_app!83
faiz_marathon_signalR_critical
Sikander Saleem 2 years ago
commit e090b9be0b

@ -11,6 +11,7 @@
"lastLoginDetails": "تفاصيل تسجيل الدخول الأخير:",
"verificationType": "نوع التحقق:",
"pleaseVerify": "ارجوك تحقق",
"pleaseVerifyForBio": "الرجاء التحقق من تسجيل الدخول باستخدام أحد هذه الخيارات",
"verifyThroughFace": "تحقق من خلال الوجه",
"verifyThroughFingerprint": "تحقق من خلال بصمة الإصبع",
"verifyThroughSMS": "تحقق من خلال الرسائل القصيرة",

@ -11,6 +11,7 @@
"lastLoginDetails": "Last Login Details:",
"verificationType": "Verification Type:",
"pleaseVerify": "Please Verify",
"pleaseVerifyForBio": "Please verify login with one of the following options",
"verifyThroughFace": "Verify Through Face",
"verifyThroughFingerprint": "Verify Through Fingerprint",
"verifyThroughSMS": "Verify Through SMS",

@ -23,7 +23,7 @@ class LoginApiClient {
postParams["DeviceType"] = deviceType;
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? responseData.mohemmGetMobileLoginInfoList!.first : null;
return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? (responseData.mohemmGetMobileLoginInfoList!.first) : null;
}, url, postParams);
}

@ -87,7 +87,7 @@ class OtpDialog {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SvgPicture.asset(
type == 1 ? "assets/images/login/verify_sms.svg" : "assets/images/login/verify_whatsapp.svg",
type == 1 ? "assets/images/login/verify_sms.svg" :type==2? "assets/images/login/verify_thumb.svg":type==3? "assets/images/login/verify_face.svg":'assets/images/login/verify_whatsapp.svg',
height: 50,
width: 50,
),

@ -13,6 +13,7 @@ abstract class LocaleKeys {
static const lastLoginDetails = 'lastLoginDetails';
static const verificationType = 'verificationType';
static const pleaseVerify = 'pleaseVerify';
static const pleaseVerifyForBio = 'pleaseVerifyForBio';
static const verifyThroughFace = 'verifyThroughFace';
static const verifyThroughFingerprint = 'verifyThroughFingerprint';
static const verifyThroughSMS = 'verifyThroughSMS';

@ -22,6 +22,11 @@ import 'package:mohem_flutter_app/models/generic_response_model.dart';
import 'package:mohem_flutter_app/models/get_mobile_login_info_list_model.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
// WhatsApp 4
// SMS 1
// Face ID 3
// Finger Print 2
class VerifyLastLoginScreen extends StatefulWidget {
VerifyLastLoginScreen({Key? key}) : super(key: key);
@ -36,6 +41,10 @@ class _VerifyLastLoginScreenState extends State<VerifyLastLoginScreen> {
List<BiometricType> _availableBioMetricType = [];
GetMobileLoginInfoListModel? mobileLoginInfoListModel;
//For face and finger print verification
int selectedFlag = 0;
bool isNeedVerifyWithFaceIDAndBiometrics = false;
@override
void initState() {
_getAvailableBiometrics();
@ -47,6 +56,7 @@ class _VerifyLastLoginScreenState extends State<VerifyLastLoginScreen> {
Widget build(BuildContext context) {
mobileLoginInfoListModel ??= ModalRoute.of(context)!.settings.arguments as GetMobileLoginInfoListModel;
String empName = AppState().isArabic(context) ? AppState().memberInformationList!.eMPLOYEEDISPLAYNAMEAr! : AppState().memberInformationList!.eMPLOYEEDISPLAYNAMEEn!;
print("selectedFlag1: " + mobileLoginInfoListModel!.loginType.toString());
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
@ -110,15 +120,16 @@ class _VerifyLastLoginScreenState extends State<VerifyLastLoginScreen> {
),
),
LocaleKeys.pleaseVerify.tr().toText16(),
if (isNeedVerifyWithFaceIDAndBiometrics) LocaleKeys.pleaseVerifyForBio.tr().toText12(),
GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9),
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.only(top: 9),
shrinkWrap: true,
children: [
getButton(3),
if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(3),
if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(2),
getButton(4),
getButton(2),
getButton(1),
],
)
@ -221,62 +232,32 @@ class _VerifyLastLoginScreenState extends State<VerifyLastLoginScreen> {
// isMoreOption = true;
});
} else {
try {
Utils.showLoading(context);
if (_flag == 4 || _flag == 3) {
if (_flag == 2 || _flag == 3) {
bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics();
if (authenticateWithFaceAndTouchID) {
Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route<dynamic> route) => false);
if (!authenticateWithFaceAndTouchID) {
return;
} else {
Utils.hideLoading(context);
if (mobileLoginInfoListModel!.loginType == 2 || mobileLoginInfoListModel!.loginType == 3) {
bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics();
if (!authenticateWithFaceAndTouchID) {
return;
} else {
performApiCall(_title, _icon, _flag, isDirectLogin: true);
}
} else {
isNeedVerifyWithFaceIDAndBiometrics = true;
selectedFlag = _flag;
setState(() {
return;
});
}
await LoginApiClient().checkMobileAppVersion();
await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!);
BasicMemberInformationModel? memberInformationModel = await LoginApiClient().mohemmSendActivationCodeByOTPNotificationType(
checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName);
Utils.hideLoading(context);
OtpDialog(
context,
_flag,
int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""),
(value) async {
Utils.showLoading(context);
try {
GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(false, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName);
GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW(
AppState().memberLoginList?.pEMAILADDRESS ?? "",
genericResponseModel?.pSESSIONID ?? 0,
genericResponseModel?.memberInformationList![0].eMPLOYEENAME ?? "",
_flag,
AppState().memberLoginList?.pMOBILENUMBER ?? "",
AppState().getUserName!,
mobileLoginInfoListModel!.deviceToken!,
Platform.isAndroid ? "android" : "ios");
if (genericResponseModel?.errorMessage != null) {
Utils.showToast(genericResponseModel?.errorMessage ?? "");
// Navigator.pop(context);
}
Utils.hideLoading(context);
Navigator.pop(context);
Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route<dynamic> route) => false);
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
},
() => {
Navigator.pop(context),
},
).displayDialog(context);
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
} else {
if (isNeedVerifyWithFaceIDAndBiometrics)
performApiCall(_title, _icon, selectedFlag);
else
performApiCall(_title, _icon, _flag);
}
// authenticateUser(_flag, isActive: _loginIndex);
}
},
child: Container(
@ -305,14 +286,14 @@ class _VerifyLastLoginScreenState extends State<VerifyLastLoginScreen> {
Widget getButton(int flag) {
switch (flag) {
case 2:
return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null);
case 1:
return _loginOptionButton(LocaleKeys.verifyThroughSMS.tr(), 'assets/images/login/verify_sms.svg', flag, null);
case 4:
case 2:
return _loginOptionButton(LocaleKeys.verifyThroughFingerprint.tr(), 'assets/images/login/verify_thumb.svg', flag, BiometricType.fingerprint.index);
case 3:
return _loginOptionButton(LocaleKeys.verifyThroughFace.tr(), 'assets/images/login/verify_face.svg', flag, BiometricType.face.index);
case 4:
return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null);
default:
return const SizedBox();
}
@ -328,6 +309,66 @@ class _VerifyLastLoginScreenState extends State<VerifyLastLoginScreen> {
}
return isAvailable;
}
Future<void> performApiCall(String _title, String _icon, int _flag, {bool isDirectLogin = false}) async {
try {
if (isDirectLogin)
setState(() {
Utils.showLoading(context);
});
else
Utils.showLoading(context);
await LoginApiClient().checkMobileAppVersion();
await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!);
if (!isDirectLogin)
BasicMemberInformationModel? memberInformationModel = await LoginApiClient()
.mohemmSendActivationCodeByOTPNotificationType(checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName);
if (isDirectLogin) performDirectApiCall(_title, _icon, _flag, "");
if (!isDirectLogin) Utils.hideLoading(context);
if (!isDirectLogin)
OtpDialog(
context,
_flag,
int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""),
(value) async {
Utils.showLoading(context);
performDirectApiCall(_title, _icon, _flag, value);
},
() => {
Navigator.pop(context),
},
).displayDialog(context);
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
}
Future<void> performDirectApiCall(String _title, String _icon, int _flag, String value, {bool isDirectLogin = false}) async {
try {
GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(false, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName);
GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW(
AppState().memberLoginList?.pEMAILADDRESS ?? "",
genericResponseModel?.pSESSIONID ?? 0,
genericResponseModel?.memberInformationList![0].eMPLOYEENAME ?? "",
_flag,
AppState().memberLoginList?.pMOBILENUMBER ?? "",
AppState().getUserName!,
mobileLoginInfoListModel!.deviceToken!,
Platform.isAndroid ? "android" : "ios");
if (genericResponseModel?.errorMessage != null) {
Utils.showToast(genericResponseModel?.errorMessage ?? "");
// Navigator.pop(context);
}
Utils.hideLoading(context);
Navigator.pop(context);
Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route<dynamic> route) => false);
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
}
//
// formatDate(date) {
// return date;

@ -13,6 +13,7 @@ import 'package:mohem_flutter_app/classes/consts.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/config/routes.dart';
import 'package:mohem_flutter_app/dialogs/otp_dialog.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/basic_member_information_model.dart';
@ -20,6 +21,11 @@ import 'package:mohem_flutter_app/models/generic_response_model.dart';
import 'package:mohem_flutter_app/models/member_information_list_model.dart';
import 'package:mohem_flutter_app/models/privilege_list_model.dart';
// WhatsApp 4
// SMS 1
// Face ID 3
// Finger Print 2
class VerifyLoginScreen extends StatefulWidget {
VerifyLoginScreen({Key? key}) : super(key: key);
@ -35,6 +41,10 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
String? firebaseToken;
//For face and finger print verification
int selectedFlag = 0;
bool isNeedVerifyWithFaceIDAndBiometrics = false;
@override
void initState() {
_getAvailableBiometrics();
@ -59,15 +69,16 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
physics: const BouncingScrollPhysics(),
children: [
LocaleKeys.pleaseVerify.tr().toText16(),
if (isNeedVerifyWithFaceIDAndBiometrics) LocaleKeys.pleaseVerifyForBio.tr().toText12(),
GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9),
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.only(top: 9),
shrinkWrap: true,
children: [
getButton(3),
if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(3),
if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(2),
getButton(4),
getButton(2),
getButton(1),
],
)
@ -500,6 +511,7 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
// }
//
Future<bool> loginWithFaceIDAndBiometrics() async {
IOSAuthMessages iosStrings =
const IOSAuthMessages(cancelButton: 'cancel', goToSettingsButton: 'settings', goToSettingsDescription: 'Please set up your Touch ID.', lockOut: 'Please reenable your Touch ID');
@ -525,18 +537,82 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
// isMoreOption = true;
});
} else {
try {
Utils.showLoading(context);
if (_flag == 4 || _flag == 3) {
if (_flag == 2 || _flag == 3) {
bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics();
if (!authenticateWithFaceAndTouchID) {
return;
} else {
isNeedVerifyWithFaceIDAndBiometrics = true;
selectedFlag = _flag;
setState(() {
return;
});
}
} else {
if (isNeedVerifyWithFaceIDAndBiometrics)
performApiCall(_title, _icon, selectedFlag);
else
performApiCall(_title, _icon, _flag);
}
}
},
child: Container(
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 28),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: isDisable ? Colors.grey.withOpacity(0.3) : Colors.white,
border: Border.all(color: MyColors.lightGreyEFColor, width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SvgPicture.asset(
_icon,
height: 38,
width: 38,
color: isDisable ? MyColors.darkTextColor.withOpacity(0.7) : null,
),
_title.toText16()
],
),
),
);
}
Widget getButton(int flag) {
switch (flag) {
case 1:
return _loginOptionButton(LocaleKeys.verifyThroughSMS.tr(), 'assets/images/login/verify_sms.svg', flag, null);
case 2:
return _loginOptionButton(LocaleKeys.verifyThroughFingerprint.tr(), 'assets/images/login/verify_thumb.svg', flag, BiometricType.fingerprint.index);
case 3:
return _loginOptionButton(LocaleKeys.verifyThroughFace.tr(), 'assets/images/login/verify_face.svg', flag, BiometricType.face.index);
case 4:
return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null);
default:
return const SizedBox();
}
}
bool checkBiometricIsAvailable(BiometricType biometricType) {
bool isAvailable = false;
for (int i = 0; i < _availableBioMetricType.length; i++) {
if (biometricType == _availableBioMetricType[i]) {
isAvailable = true;
break;
}
}
return isAvailable;
}
Future<void> performApiCall(String _title, String _icon, int _flag) async {
try {
Utils.showLoading(context);
await LoginApiClient().checkMobileAppVersion();
await LoginApiClient().memberLogin(AppState().getUserName!, AppState().password!);
BasicMemberInformationModel? memberInformationModel = await LoginApiClient().mohemmSendActivationCodeByOTPNotificationType(
checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName);
BasicMemberInformationModel? memberInformationModel = await LoginApiClient()
.mohemmSendActivationCodeByOTPNotificationType(checkBiometricIsAvailable(BiometricType.fingerprint) ? 1 : 0, AppState().memberLoginList?.pMOBILENUMBER, _flag, AppState().getUserName);
Utils.hideLoading(context);
OtpDialog(
context,
@ -590,56 +666,6 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
Utils.handleException(ex, context, null);
}
}
},
child: Container(
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 28),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: isDisable ? Colors.grey.withOpacity(0.3) : Colors.white,
border: Border.all(color: MyColors.lightGreyEFColor, width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SvgPicture.asset(
_icon,
height: 38,
width: 38,
color: isDisable ? MyColors.darkTextColor.withOpacity(0.7) : null,
),
_title.toText16()
],
),
),
);
}
Widget getButton(int flag) {
switch (flag) {
case 2:
return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null);
case 1:
return _loginOptionButton(LocaleKeys.verifyThroughSMS.tr(), 'assets/images/login/verify_sms.svg', flag, null);
case 4:
return _loginOptionButton(LocaleKeys.verifyThroughFingerprint.tr(), 'assets/images/login/verify_thumb.svg', flag, BiometricType.fingerprint.index);
case 3:
return _loginOptionButton(LocaleKeys.verifyThroughFace.tr(), 'assets/images/login/verify_face.svg', flag, BiometricType.face.index);
default:
return const SizedBox();
}
}
bool checkBiometricIsAvailable(BiometricType biometricType) {
bool isAvailable = false;
for (int i = 0; i < _availableBioMetricType.length; i++) {
if (biometricType == _availableBioMetricType[i]) {
isAvailable = true;
break;
}
}
return isAvailable;
}
//
// formatDate(date) {
// return date;

Loading…
Cancel
Save