diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index bb4911f1..11a2ecc0 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -3,14 +3,14 @@ class URLs { static const String appReleaseBuildNumber = "23"; - static const host1 = "https://atomsm.hmg.com"; // production url + // static const host1 = "https://atomsm.hmg.com"; // production url // static const host1 = "https://atomsmdev.hmg.com"; // local DEV url - // static const host1 = "https://atomsmuat.hmg.com"; // local UAT url + static const host1 = "https://atomsmuat.hmg.com"; // local UAT url // static String _baseUrl = "$_host/mobile"; // static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis - // static final String _baseUrl = "$_host/mobile"; // host local UAT - static final String _baseUrl = "$_host/v3/mobile"; // v3 for new CM,PM,TM + static final String _baseUrl = "$_host/mobile"; // host local UAT + // static final String _baseUrl = "$_host/v3/mobile"; // v3 for new CM,PM,TM static String _host = host1; @@ -22,7 +22,9 @@ class URLs { // API Routes static get login => "$_baseUrl/MobileAuth/Login"; + static get getUserInfo => "$_baseUrl/MobileAuth/GetUserInfo"; static get logout => "$_baseUrl/MobileAuth/Logout"; + static get enableFaceId => "$_baseUrl/MobileAuth/EnabledFaceId"; static get checkLoginValidation => "$_baseUrl/Account/Authenticate"; // web login static get checkAppVersion => "$_baseUrl/Account/CheckAppVersion"; // web login //Reset Password Apis... diff --git a/lib/controllers/providers/api/user_provider.dart b/lib/controllers/providers/api/user_provider.dart index a8f0a52c..94813149 100644 --- a/lib/controllers/providers/api/user_provider.dart +++ b/lib/controllers/providers/api/user_provider.dart @@ -32,6 +32,10 @@ class UserProvider extends ChangeNotifier { User? get user => _user; + User? _refreshedUser; + + User? get refreshedUser => _refreshedUser; + File? profileImage; VerifyOtpModel _verifyOtpModel = VerifyOtpModel(); @@ -117,6 +121,37 @@ class UserProvider extends ChangeNotifier { } } + + Future getUserInfo({ String? fireBaseToken}) async { + // if (_loading == true) return false; + // _loading = true; + notifyListeners(); + Response response; + try { + response = await ApiManager.instance.post(URLs.getUserInfo,body: { + 'fireBaseToken':fireBaseToken, + }); + // _loading = false; + if (response.statusCode >= 200 && response.statusCode < 300) { + _refreshedUser = await User.fromJson(jsonDecode(response.body)); + _refreshedUser!.profilePhotoName = URLs.getFileUrl(_user!.profilePhotoName); + notifyListeners(); + if (response.statusCode == 200) { + return true; + } + } + notifyListeners(); + return false; + } catch (error) { + print('SSL or Network Error: $error'); + // _loading = false; + notifyListeners(); + return false; + } + } + + + Future logout(BuildContext context) async { Response response; try { diff --git a/lib/controllers/providers/settings/setting_provider.dart b/lib/controllers/providers/settings/setting_provider.dart index 6e1a1e87..2ca13b42 100644 --- a/lib/controllers/providers/settings/setting_provider.dart +++ b/lib/controllers/providers/settings/setting_provider.dart @@ -178,6 +178,22 @@ class SettingProvider extends ChangeNotifier { } } + + Future checkIsEnabledFaceId({required bool status}) async { + try { + final response = await ApiManager.instance.post( + URLs.enableFaceId, + body: { + 'isEnabled':status, + }, + ); + return response.statusCode >= 200 && response.statusCode < 300; + } catch (error) { + return false; + } + } + + Future checkAppUpdate(String buildNumber, String osType) async { Response response; bool isValid = false; diff --git a/lib/dashboard_latest/dashboard_view.dart b/lib/dashboard_latest/dashboard_view.dart index 149a9e24..3e399e41 100644 --- a/lib/dashboard_latest/dashboard_view.dart +++ b/lib/dashboard_latest/dashboard_view.dart @@ -103,7 +103,7 @@ class _DashboardViewState extends State { @override Widget build(BuildContext context) { - bool isNurse = (Provider.of(context, listen: false).user!.type) == UsersTypes.normal_user; + bool isNurse = (Provider.of(context, listen: false).user?.type) == UsersTypes.normal_user; final user = Provider.of(context, listen: false).user; return Stack( children: [ diff --git a/lib/models/user.dart b/lib/models/user.dart index 75045ac0..a1ed40b0 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -42,6 +42,7 @@ class User { bool? enableWifi; bool? enableNFC; bool? enableQR; + bool? isEnabledFaceId; bool? onlySwipe; User({ @@ -79,6 +80,7 @@ class User { this.enableNFC, this.enableQR, this.enableWifi, + this.isEnabledFaceId, this.onlySwipe, }); @@ -86,9 +88,12 @@ class User { Future> toLoginJson() async { String notificationType = (Platform.isAndroid && !(await FirebaseNotificationManger.isGoogleServicesAvailable())) ? "HMC" : "FCM"; + if(FirebaseNotificationManger.token==null){ + //calling this agin to check for token as sometimes token is null fresh install.. + await FirebaseNotificationManger.getToken(); + } return {"username": userName, "password": password, "fireBaseToken": FirebaseNotificationManger?.token ?? "", "notificationType": notificationType}; } - UsersTypes? get type { switch (userRoles?.first.value) { case "R-6": @@ -167,6 +172,7 @@ class User { map['enableNFC'] = enableNFC; map['enableQR'] = enableQR; map['onlySwipe'] = onlySwipe; + map['isEnabledFaceId'] = isEnabledFaceId; return map; } @@ -233,6 +239,7 @@ class User { enableNFC = json['enableNFC']; enableQR = json['enableQR']; onlySwipe = json['onlySwipe']; + isEnabledFaceId = json['isEnabledFaceId']; } } @@ -300,6 +307,14 @@ class AssetGroup { data['enabledEngineerTimer'] = enabledEngineerTimer; return data; } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is AssetGroup && runtimeType == other.runtimeType && id == other.id; + + @override + int get hashCode => id.hashCode; } class UserContactInfoModel { diff --git a/lib/new_views/pages/login_page.dart b/lib/new_views/pages/login_page.dart index 304daf92..1cc6905f 100644 --- a/lib/new_views/pages/login_page.dart +++ b/lib/new_views/pages/login_page.dart @@ -233,8 +233,17 @@ class _LoginPageState extends State { int status = await _userProvider.login(context: context, user: _user); if (status >= 200 && status < 300 && _userProvider.user!.isAuthenticated! ?? false) { await _settingProvider!.setUser(_userProvider.user!); - (await SharedPreferences.getInstance()).remove(ASettings.localAuth); + + // (await SharedPreferences.getInstance()).remove(ASettings.localAuth); await _settingProvider!.setRememberMe(_user.userName!, _user.password!, rememberMe); + //TODO need to verify this here... + if(_userProvider.user?.isEnabledFaceId==true){ + await _settingProvider!.setAuth(_userProvider.user!.isEnabledFaceId!); + }else{ + (await SharedPreferences.getInstance()).remove(ASettings.localAuth); + } + + Navigator.pushReplacementNamed(context, LandPage.routeName); } else { Fluttertoast.showToast(msg: _userProvider.user?.message ?? context.translation.failedToCompleteRequest); diff --git a/lib/new_views/pages/settings_page.dart b/lib/new_views/pages/settings_page.dart index 3cdaad4b..5e6e162d 100644 --- a/lib/new_views/pages/settings_page.dart +++ b/lib/new_views/pages/settings_page.dart @@ -51,6 +51,7 @@ class _SettingsPageState extends State { if (authStatus) { localAuth = !localAuth; await _settingProvider!.setAuth(localAuth); + await _settingProvider!.checkIsEnabledFaceId(status: localAuth); // authController.value = _settingProvider.localAuth == buttonState.toString(); setState(() {}); } else { diff --git a/lib/new_views/pages/splash_page.dart b/lib/new_views/pages/splash_page.dart index ec2bfe10..2823fdef 100644 --- a/lib/new_views/pages/splash_page.dart +++ b/lib/new_views/pages/splash_page.dart @@ -1,6 +1,8 @@ +import 'dart:developer'; import 'dart:io'; import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flare_flutter/flare_actor.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -40,6 +42,7 @@ class _SplashPageState extends State { @override void initState() { Firebase.initializeApp(); + // NotificationManger.initialisation((notificationDetails) { // // todo @sikander, check notifications payload, because notification model is different to need to check from backend // // SystemNotificationModel notification = SystemNotificationModel.fromJson(json.decode(notificationDetails.payload)); @@ -116,8 +119,16 @@ class _SplashPageState extends State { } if (isSuccess) { - _userProvider.setUser(_settingProvider.user!); - + _userProvider.setUser(_settingProvider.user!); + if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken(); + await _userProvider.getUserInfo(fireBaseToken:FirebaseNotificationManger.token).then((status) async{ + if(status&&_userProvider.refreshedUser!=null){ + _userProvider.refreshedUser!.token = _settingProvider.user?.token; + await _settingProvider.setUser(_userProvider.refreshedUser!); + _userProvider.setUser(_settingProvider.user!); + await _settingProvider.setAuth(_settingProvider.user?.isEnabledFaceId??false); + } + }); if (_userProvider.user!.onlySwipe!) { Navigator.of(context).pushNamedAndRemoveUntil(SwipeView.routeName, (routes) => true); } else { diff --git a/lib/views/widgets/images/multi_image_picker.dart b/lib/views/widgets/images/multi_image_picker.dart index 470471a1..1bddd87e 100644 --- a/lib/views/widgets/images/multi_image_picker.dart +++ b/lib/views/widgets/images/multi_image_picker.dart @@ -475,10 +475,11 @@ class _AttachmentPickerState extends State { } onFilePicker() async { - if (widget.attachment.length >= 5) { - Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); - return; - } + //TODO removed on request by Backend as they don't have anyissue with large number of files + // if (widget.attachment.length >= 5) { + // Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); + // return; + // } ImageSource? source = await showModalBottomSheet( context: context, builder: (BuildContext context) {