From 8ff6f7656cecb7c76ffda67d20fd957ae85bfa3d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 14 Sep 2018 12:11:19 -0700 Subject: [PATCH] Authentcation --- lib/main.dart | 2 +- lib/ui/settings/settings_list_vm.dart | 27 ++++++++++++++++++++------- lib/utils/localization.dart | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index c9aba1ea9..4200fc14a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -166,7 +166,7 @@ class InvoiceNinjaAppState extends State { children: [ Icon( FontAwesomeIcons.lock, - size: 26.0, + size: 24.0, color: Colors.grey[400], ), SizedBox( diff --git a/lib/ui/settings/settings_list_vm.dart b/lib/ui/settings/settings_list_vm.dart index 948e38298..abcdd6253 100644 --- a/lib/ui/settings/settings_list_vm.dart +++ b/lib/ui/settings/settings_list_vm.dart @@ -9,6 +9,7 @@ import 'package:invoiceninja_flutter/ui/app/app_builder.dart'; import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart'; +import 'package:local_auth/local_auth.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/ui/auth/login_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/settings_list.dart'; @@ -101,15 +102,27 @@ class SettingsListVM { store.dispatch(UserSettingsChanged(enableDarkMode: value)); AppBuilder.of(context).rebuild(); }, - onRequireAuthenticationChanged: - (BuildContext context, bool value) async { - final SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setBool(kSharedPrefRequireAuthentication, value); - store.dispatch(UserSettingsChanged(requireAuthentication: value)); + onRequireAuthenticationChanged: (BuildContext context, bool value) async { + bool authenticated = false; + try { + authenticated = await LocalAuthentication() + .authenticateWithBiometrics( + localizedReason: 'Please authenticate to change the setting', + useErrorDialogs: true, + stickyAuth: false); + } catch (e) { + print(e); + } + if (authenticated) { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setBool(kSharedPrefRequireAuthentication, value); + store.dispatch(UserSettingsChanged(requireAuthentication: value)); + } else { + + } }, enableDarkMode: store.state.uiState.enableDarkMode, - requireAuthentication: - store.state.uiState.requireAuthentication, + requireAuthentication: store.state.uiState.requireAuthentication, ); } } diff --git a/lib/utils/localization.dart b/lib/utils/localization.dart index 834ed37d3..be3ee5798 100644 --- a/lib/utils/localization.dart +++ b/lib/utils/localization.dart @@ -14,6 +14,7 @@ class AppLocalization { static final Map> _localizedValues = { 'en': { + 'locked': 'Locked', 'authenticate': 'Authenticate', 'please_authenticate': 'Please authenticate',