Biometric Auth

localization_aamir
Aamir.Muhammad 2 years ago
parent 7ab427e113
commit 3ca0b9776b

@ -75,8 +75,8 @@ class ApiClientImp implements ApiClient {
headers0.addAll(headers); headers0.addAll(headers);
} }
if (!kReleaseMode) { if (!kReleaseMode) {
log("Url:$url"); logger.i("Url:$url");
log("body:$jsonObject"); logger.i("body:$jsonObject");
} }
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers0, retryTimes: retryTimes); var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers0, retryTimes: retryTimes);
try { try {
@ -240,8 +240,8 @@ class ApiClientImp implements ApiClient {
} }
if (!kReleaseMode) { if (!kReleaseMode) {
log("Url:$url"); logger.i("Url:$url");
log("queryParameters:$queryParameters"); logger.i("queryParameters:$queryParameters");
} }
var response = await _get(Uri.parse(url), headers: headers0).timeout(const Duration(seconds: 60)); var response = await _get(Uri.parse(url), headers: headers0).timeout(const Duration(seconds: 60));

@ -1,7 +1,12 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:huawei_fido/huawei_fido.dart';
import 'package:local_auth/local_auth.dart'; import 'package:local_auth/local_auth.dart';
import 'package:local_auth_android/local_auth_android.dart'; import 'package:local_auth_android/local_auth_android.dart';
import 'package:local_auth_ios/local_auth_ios.dart'; import 'package:local_auth_darwin/types/auth_messages_ios.dart';
import 'package:mc_common_app/main.dart';
abstract class CommonAuthServices { abstract class CommonAuthServices {
Future<bool> authenticate(); Future<bool> authenticate();
@ -51,6 +56,14 @@ class CommonAuthImp implements CommonAuthServices {
} }
Future<List<BiometricType>> getAvailBio() async { Future<List<BiometricType>> getAvailBio() async {
return await localAuth.getAvailableBiometrics(); return await localAuth.getAvailableBiometrics();
}
Future<void> getHuaweiAuth() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
// if (androidInfo.brand == "HUAWEI") {
// huawei.canAuth();
// }
} }
} }

@ -1,9 +1,11 @@
import 'dart:convert'; import 'dart:convert';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:huawei_fido/huawei_fido.dart';
import 'package:local_auth/local_auth.dart'; import 'package:local_auth/local_auth.dart';
import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/classes/app_state.dart';
import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/classes/consts.dart';
@ -331,51 +333,92 @@ class UserVM extends BaseVM {
} }
} }
Future<void> performBasicOtpLoginSelectionPage(BuildContext context, {required String userToken, required AppType appType}) async { Future<void> performBasicOtpLoginSelectionPage(BuildContext context, {required String userToken, required AppType appType, String? loginType}) async {
Utils.showLoading(context); if (loginType == "3" || loginType == "4") {
LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, "1"); Utils.showLoading(context);
Utils.hideLoading(context); LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, loginType!);
if (user.messageStatus == 1) { Utils.hideLoading(context);
showMDialog(context, child: OtpDialog( if (user.messageStatus == 1) {
onClick: (String code) async { Utils.showLoading(context);
pop(context); Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", "9999");
Utils.showLoading(context); Utils.hideLoading(context);
Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", code); RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body));
Utils.hideLoading(context); if (verifiedUser.messageStatus == 1) {
RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body)); User user = User.fromJson(jsonDecode(response2.body));
if (verifiedUser.messageStatus == 1) { if (appType == AppType.provider) {
User user = User.fromJson(jsonDecode(response2.body)); if (user.data!.userInfo!.roleId == 5 || user.data!.userInfo!.roleId == 6) {
if (appType == AppType.provider) { AppState().setUser = user;
if (user.data!.userInfo!.roleId == 5 || user.data!.userInfo!.roleId == 6) { SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
AppState().setUser = user; SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
SharedPrefManager.setUserToken(user.data!.accessToken ?? ""); SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? ""); SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? ""); navigateReplaceWithName(context, AppRoutes.dashboard);
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson())); } else {
navigateReplaceWithName(context, AppRoutes.dashboard); Utils.showToast("LocaleKeys.onlyProviderApp.tr()");
} else { //("Sorry, Only Customer's can log in this app");
Utils.showToast("LocaleKeys.onlyProviderApp.tr()"); }
//("Sorry, Only Customer's can log in this app"); } else if (user.data!.userInfo!.roleId == 4) {
} if (user.data!.userInfo!.roleId == 4) {
} else if (user.data!.userInfo!.roleId == 4) { AppState().setUser = user;
if (user.data!.userInfo!.roleId == 4) { SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
AppState().setUser = user; SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
SharedPrefManager.setUserToken(user.data!.accessToken ?? ""); SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? ""); SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? ""); navigateReplaceWithName(context, AppRoutes.dashboard);
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson())); } else {
navigateReplaceWithName(context, AppRoutes.dashboard); Utils.showToast("Sorry, Only Customer's can log in this app");
} else {
Utils.showToast("Sorry, Only Customer's can log in this app");
}
} }
} else {
Utils.showToast(verifiedUser.message ?? "");
} }
}, } else {
)); Utils.showToast(verifiedUser.message ?? "");
}
}
} else { } else {
Utils.showToast(user.message ?? ""); Utils.showLoading(context);
LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, "1");
Utils.hideLoading(context);
if (user.messageStatus == 1) {
showMDialog(context, child: OtpDialog(
onClick: (String code) async {
pop(context);
Utils.showLoading(context);
Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", code);
Utils.hideLoading(context);
RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body));
if (verifiedUser.messageStatus == 1) {
User user = User.fromJson(jsonDecode(response2.body));
if (appType == AppType.provider) {
if (user.data!.userInfo!.roleId == 5 || user.data!.userInfo!.roleId == 6) {
AppState().setUser = user;
SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
navigateReplaceWithName(context, AppRoutes.dashboard);
} else {
Utils.showToast("LocaleKeys.onlyProviderApp.tr()");
//("Sorry, Only Customer's can log in this app");
}
} else if (user.data!.userInfo!.roleId == 4) {
if (user.data!.userInfo!.roleId == 4) {
AppState().setUser = user;
SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
navigateReplaceWithName(context, AppRoutes.dashboard);
} else {
Utils.showToast("Sorry, Only Customer's can log in this app");
}
}
} else {
Utils.showToast(verifiedUser.message ?? "");
}
},
));
} else {
Utils.showToast(user.message ?? "");
}
} }
} }
@ -515,10 +558,15 @@ class UserVM extends BaseVM {
// Aamir Code // Aamir Code
List<BiometricType>? availBio; List<BiometricType>? availBio;
Future<void> verifiyAuth({BuildContext? context, String? userToken, AppType? apptype}) async { Future<void> verifiyAuth({
BuildContext? context,
String? userToken,
AppType? apptype,
String? loginType,
}) async {
bool auth = await CommonAuthImp().authenticate(); bool auth = await CommonAuthImp().authenticate();
if (auth) { if (auth) {
performBasicOtpLoginSelectionPage(context!, userToken: userToken!, appType: apptype!); performBasicOtpLoginSelectionPage(context!, userToken: userToken!, appType: apptype!, loginType: loginType);
} }
} }
@ -527,7 +575,6 @@ class UserVM extends BaseVM {
} }
bool isBioAvailable(BiometricType bioType) { bool isBioAvailable(BiometricType bioType) {
logger.d(availBio);
if (availBio == null) return true; if (availBio == null) return true;
if (availBio!.contains(bioType)) { if (availBio!.contains(bioType)) {
return false; return false;

@ -54,12 +54,12 @@ class _LoginMethodSelectionPageState extends State<LoginMethodSelectionPage> {
Expanded( Expanded(
child: ShowImageButton( child: ShowImageButton(
onClick: () { onClick: () {
userVM.verifiyAuth(context: context, userToken: widget.userToken, apptype: appState.currentAppType); userVM.verifiyAuth(context: context, userToken: widget.userToken, apptype: appState.currentAppType, loginType: "3" );
//userVM.performBasicOtpLoginSelectionPage(context, userToken: userToken,appType: appState.currentAppType); //userVM.performBasicOtpLoginSelectionPage(context, userToken: userToken,appType: appState.currentAppType);
}, },
title: LocaleKeys.fingerPrint.tr(), title: LocaleKeys.fingerPrint.tr(),
icon: MyAssets.icFingerprintSvg, icon: MyAssets.icFingerprintSvg,
isDisabled: userVM.isBioAvailable(Platform.isAndroid ? BiometricType.weak : BiometricType.fingerprint), isDisabled: userVM.isBioAvailable(Platform.isAndroid ? BiometricType.weak : BiometricType.fingerprint, ),
), ),
), ),
20.width, 20.width,
@ -67,7 +67,7 @@ class _LoginMethodSelectionPageState extends State<LoginMethodSelectionPage> {
child: ShowImageButton( child: ShowImageButton(
onClick: () { onClick: () {
// userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType); // userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType);
userVM.verifiyAuth(context: context, userToken: widget.userToken, apptype: appState.currentAppType); userVM.verifiyAuth(context: context, userToken: widget.userToken, apptype: appState.currentAppType, loginType: "4" );
}, },
title: LocaleKeys.faceRecognition.tr(), title: LocaleKeys.faceRecognition.tr(),
icon: MyAssets.icFace, icon: MyAssets.icFace,
@ -82,7 +82,7 @@ class _LoginMethodSelectionPageState extends State<LoginMethodSelectionPage> {
Expanded( Expanded(
child: ShowImageButton( child: ShowImageButton(
onClick: () { onClick: () {
userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType); userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType,loginType: "1");
}, },
title: LocaleKeys.SMS.tr(), title: LocaleKeys.SMS.tr(),
icon: MyAssets.icSmsSvg, icon: MyAssets.icSmsSvg,
@ -93,7 +93,7 @@ class _LoginMethodSelectionPageState extends State<LoginMethodSelectionPage> {
child: ShowImageButton( child: ShowImageButton(
onClick: () { onClick: () {
// navigateWithName(context, AppRoutes.dashboard); // navigateWithName(context, AppRoutes.dashboard);
userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType); userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType, loginType: "2");
}, },
title: LocaleKeys.whatsapp.tr(), title: LocaleKeys.whatsapp.tr(),
icon: MyAssets.icWhatsAppSvg, icon: MyAssets.icWhatsAppSvg,

File diff suppressed because it is too large Load Diff

@ -18,7 +18,6 @@ dependencies:
easy_localization: ^3.0.3 easy_localization: ^3.0.3
http: ^0.13.3 http: ^0.13.3
permission_handler: ^10.2.0 permission_handler: ^10.2.0
device_info_plus: any
flutter_svg: ^1.0.3 flutter_svg: ^1.0.3
sizer: ^2.0.15 sizer: ^2.0.15
fluttertoast: ^8.0.8 fluttertoast: ^8.0.8
@ -29,7 +28,6 @@ dependencies:
logger: 2.3.0 logger: 2.3.0
auto_size_text: any auto_size_text: any
shimmer: ^2.0.0 shimmer: ^2.0.0
local_auth: any
hexcolor: ^3.0.1 hexcolor: ^3.0.1
cached_network_image: any cached_network_image: any
url_launcher: ^6.1.14 url_launcher: ^6.1.14
@ -53,7 +51,10 @@ dependencies:
# Auth # Auth
local_auth: ^2.2.0
local_auth: ^2.2.0
huawei_fido: ^6.3.0+305
device_info_plus: ^10.1.0
dev_dependencies: dev_dependencies:

Loading…
Cancel
Save