From cfa016210968f8c134af388e92ab568ef619d9e5 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 26 Mar 2020 14:37:47 +0200 Subject: [PATCH] implement basic verifecation type --- lib/config/shared_pref_kay.dart | 0 lib/providers/auth_provider.dart | 19 +++- lib/widgets/auth/known_user_login.dart | 125 ++++++++++++++++++------- pubspec.yaml | 3 + 4 files changed, 113 insertions(+), 34 deletions(-) create mode 100644 lib/config/shared_pref_kay.dart diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart index 30235a96..6d551f05 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -9,7 +9,7 @@ const LOGIN_URL = 'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New'; const INSERT_DEVICE_IMEI = 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; - +const SELECT_DEVICE_IMEI ='https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; class AuthProvider with ChangeNotifier { Future login(UserModel userInfo) async { Map requestHeaders = { @@ -54,4 +54,21 @@ class AuthProvider with ChangeNotifier { throw error; } } + + Future selectDeviceImei(imei) async { + Map requestHeaders = { + 'Content-type': 'application/json', + 'Accept': 'application/json', + }; + const url = SELECT_DEVICE_IMEI; + + try { + final response = await http.post(url, + headers: requestHeaders, body: json.encode(imei)); + return Future.value(json.decode(response.body)); + } catch (error) { + print(error); + throw error; + } + } } diff --git a/lib/widgets/auth/known_user_login.dart b/lib/widgets/auth/known_user_login.dart index 881df25c..1888f7ba 100644 --- a/lib/widgets/auth/known_user_login.dart +++ b/lib/widgets/auth/known_user_login.dart @@ -1,20 +1,22 @@ -import 'dart:collection'; -import 'dart:ffi'; - -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/routes.dart'; -import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; -import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; -import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; +import 'package:doctor_app_flutter/lookups/auth_lookup.dart'; +import 'package:doctor_app_flutter/providers/auth_provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:local_auth/local_auth.dart'; +import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../../config/config.dart'; +import '../../routes.dart'; +import '../../util/dr_app_shared_pref.dart'; +import '../../util/dr_app_toast_msg.dart'; +import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; + DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppToastMsg toastMsg = DrAppToastMsg(); + class KnownUserLogin extends StatefulWidget { @override _KnownUserLoginState createState() => _KnownUserLoginState(); @@ -23,32 +25,49 @@ class KnownUserLogin extends StatefulWidget { class _KnownUserLoginState extends State { Future _prefs = SharedPreferences.getInstance(); final LocalAuthentication auth = LocalAuthentication(); + String _authorized = "not Authorized"; bool _isAuthenticating = false; - Future loggedUserFuture; - var loggedUser; + Future _loggedUserFuture; + var _loggedUser; + int _loginType; + + Map _loginTypeMap = { + 1: { + "name": "SMS", + 'imageUrl': 'assets/images/verification_sms_lg_icon.png', + }, + 2: { + "name": "FingerPrint", + 'imageUrl': 'assets/images/verification_fingerprint_lg_icon.png' + }, + 3: {"name": "Face", 'imageUrl': 'assets/images/verification_faceid_lg_icon.png'}, + 4: {"name": "WhatsApp", 'imageUrl': 'assets/images/verification_whatsapp_lg_icon.png'} + }; + Future getSharedPref() async { sharedPref.getObj('loggedUser').then((userInfo) { - // if(loggedUser == null){} - loggedUser = userInfo; - // print('dddddddddddddddd${loggedUser}'); + _loggedUser = userInfo; }); } @override void initState() { super.initState(); - loggedUserFuture = _prefs.then((SharedPreferences prefs) { + _loggedUserFuture = _prefs.then((SharedPreferences prefs) { return (prefs.getString('platformImei')); }); } @override Widget build(BuildContext context) { + getSharedPref(); + AuthProvider authProv = Provider.of(context); + selectDeviceImei(authProv); return FutureBuilder( - future: loggedUserFuture, + future: _loggedUserFuture, builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: @@ -99,7 +118,7 @@ class _KnownUserLoginState extends State { CrossAxisAlignment.start, children: [ Text( - loggedUser['List_MemberInformation'][0] + _loggedUser['List_MemberInformation'][0] ['MemberName'], style: TextStyle( color: Hexcolor('515A5D'), @@ -130,15 +149,7 @@ class _KnownUserLoginState extends State { fit: BoxFit.cover, )) ]), - Container( - height: 200, - width: 200, - child: Center( - child: Image.asset( - 'assets/images/verification_fingerprint_lg_icon.png', - fit: BoxFit.cover, - ), - )), + buildVerificationTypeImageContainer(), buildButtonsContainer( isSmallScreen, constraints, context) ], @@ -150,6 +161,19 @@ class _KnownUserLoginState extends State { }); } + Container buildVerificationTypeImageContainer() { + print('${_loginTypeMap[_loginType]}'); + return Container( + height: 200, + width: 200, + child: Center( + child: Image.asset( + _loginTypeMap[_loginType]['imageUrl'], + fit: BoxFit.cover, + ), + )); + } + // Container buildButtonsContainer( bool isSmallScreen, BoxConstraints constraints, BuildContext context) { @@ -159,14 +183,15 @@ class _KnownUserLoginState extends State { child: Column( children: [ RaisedButton( - onPressed: _silentLogin, + onPressed: _authenticate, elevation: 0.0, child: Container( width: double.infinity, height: 50, child: Center( child: Text( - "Verify using FingerPRint".toUpperCase(), + "Verify using ${_loginTypeMap[_loginType]['name']}" + .toUpperCase(), // textAlign: TextAlign.center, style: TextStyle( color: Colors.white, @@ -213,14 +238,22 @@ class _KnownUserLoginState extends State { Navigator.of(context).pushNamed('routeName'); } - _silentLogin() { - _authenticate().then((_) { - // print('$val'); - print(_authorized); - }); +_authenticate(){ + if(_loginType ==1) { + _authenticateBySMS(); } + if(_loginType ==2) { + _authenticateByFingerPrint(); + } + if(_loginType ==3) { + _authenticateByFace(); + } + if(_loginType ==4) { + _authenticateByWhatsApp(); + } +} - Future _authenticate() async { + Future _authenticateByFingerPrint() async { _getAvailableBiometrics(); bool authenticated = false; try { @@ -252,6 +285,17 @@ class _KnownUserLoginState extends State { }); } +Future _authenticateBySMS(){ + print('_authenticateBySMS'); +} +Future _authenticateByFace(){ + print('_authenticateByFace'); +} +Future _authenticateByWhatsApp(){ + print('_authenticateByWhatsApp'); + +} + Future _getAvailableBiometrics() async { List availableBiometrics; try { @@ -273,4 +317,19 @@ class _KnownUserLoginState extends State { showErorrMsg(localMsg) { toastMsg.showErrorToast(localMsg); } + + selectDeviceImei(AuthProvider authProv) { + sharedPref.getString('platformImei').then((imei) { + var imeiModel = {'IMEI': imei}; + authProv.selectDeviceImei(imeiModel).then((res) { + // setState(() { + _loginType = 4;//res['SELECTDeviceIMEIbyIMEI_List'][0]['LogInType']; + + // }); + print(_loginType.toString()); + }).catchError((err) { + print('${err}'); + }); + }); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 5270034c..cfbf8ce9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -63,6 +63,9 @@ flutter: - assets/images/login_btn_arrow_icon.png - assets/images/dr_avatar.png - assets/images/verification_fingerprint_lg_icon.png + - assets/images/verification_faceid_lg_icon.png + - assets/images/verification_sms_lg_icon.png + - assets/images/verification_whatsapp_lg_icon.png - assets/images/close_icon.png # - images/a_dot_ham.jpeg