diff --git a/lib/redux/user/user_actions.dart b/lib/redux/user/user_actions.dart index 005037523..b2ccd0167 100644 --- a/lib/redux/user/user_actions.dart +++ b/lib/redux/user/user_actions.dart @@ -272,7 +272,6 @@ void handleUserAction( } final store = StoreProvider.of(context); - final state = store.state; final localization = AppLocalization.of(context); final user = users.first as UserEntity; final userIds = users.map((user) => user.id).toList(); @@ -287,15 +286,11 @@ void handleUserAction( snackBarCompleter(context, localization.restoredUser), userIds: userIds, password: password)); - if (state.authState.hasRecentlyEnteredPassword) { - dispatch(); - } else { - passwordCallback( - context: context, - callback: (password) { - dispatch(password); - }); - } + passwordCallback( + context: context, + callback: (password) { + dispatch(password); + }); break; case EntityAction.archive: final dispatch = ([String password]) => store.dispatch(ArchiveUserRequest( @@ -303,30 +298,22 @@ void handleUserAction( snackBarCompleter(context, localization.archivedUser), userIds: userIds, password: password)); - if (state.authState.hasRecentlyEnteredPassword) { - dispatch(); - } else { - passwordCallback( - context: context, - callback: (password) { - dispatch(password); - }); - } + passwordCallback( + context: context, + callback: (password) { + dispatch(password); + }); break; case EntityAction.delete: final dispatch = ([String password]) => store.dispatch(DeleteUserRequest( completer: snackBarCompleter(context, localization.deletedUser), userIds: userIds, password: password)); - if (state.authState.hasRecentlyEnteredPassword) { - dispatch(); - } else { - passwordCallback( - context: context, - callback: (password) { - dispatch(password); - }); - } + passwordCallback( + context: context, + callback: (password) { + dispatch(password); + }); break; case EntityAction.remove: final dispatch = ([String password]) => store.dispatch(RemoveUserRequest( @@ -336,15 +323,11 @@ void handleUserAction( confirmCallback( context: context, callback: () { - if (state.authState.hasRecentlyEnteredPassword) { - dispatch(); - } else { - passwordCallback( - context: context, - callback: (password) { - dispatch(password); - }); - } + passwordCallback( + context: context, + callback: (password) { + dispatch(password); + }); }); break; case EntityAction.toggleMultiselect: diff --git a/lib/ui/settings/account_management.dart b/lib/ui/settings/account_management.dart index bd932e73d..93f42627e 100644 --- a/lib/ui/settings/account_management.dart +++ b/lib/ui/settings/account_management.dart @@ -172,6 +172,7 @@ class _AccountOverview extends StatelessWidget { message: localization.purgeDataMessage, callback: () { passwordCallback( + alwaysRequire: true, context: context, callback: (password) { viewModel.onPurgeData(context, password); @@ -248,6 +249,7 @@ class _AccountOverview extends StatelessWidget { message: message, callback: () { passwordCallback( + alwaysRequire: true, context: context, callback: (password) { viewModel.onCompanyDelete(context, password); diff --git a/lib/ui/settings/user_details_vm.dart b/lib/ui/settings/user_details_vm.dart index ac3343546..7a1b42729 100644 --- a/lib/ui/settings/user_details_vm.dart +++ b/lib/ui/settings/user_details_vm.dart @@ -50,26 +50,17 @@ class UserDetailsVM { completer.future.then((_) { AppBuilder.of(context).rebuild(); }); - if (state.authState.hasRecentlyEnteredPassword) { - store.dispatch( - SaveAuthUserRequest( - completer: completer, - user: state.uiState.settingsUIState.user, - ), - ); - } else { - passwordCallback( - context: context, - callback: (password) { - store.dispatch( - SaveAuthUserRequest( - completer: completer, - user: state.uiState.settingsUIState.user, - password: password, - ), - ); - }); - } + passwordCallback( + context: context, + callback: (password) { + store.dispatch( + SaveAuthUserRequest( + completer: completer, + user: state.uiState.settingsUIState.user, + password: password, + ), + ); + }); }, ); } diff --git a/lib/ui/system/update_dialog.dart b/lib/ui/system/update_dialog.dart index eec6f0c74..dfc6d7d5c 100644 --- a/lib/ui/system/update_dialog.dart +++ b/lib/ui/system/update_dialog.dart @@ -84,6 +84,7 @@ class _UpdateDialogState extends State { void updateApp(BuildContext context) async { final state = StoreProvider.of(context).state; passwordCallback( + alwaysRequire: true, context: context, callback: (password) { setState(() => updateState = UpdateState.loading); diff --git a/lib/ui/user/edit/user_edit_vm.dart b/lib/ui/user/edit/user_edit_vm.dart index eaeff916c..a12ac21af 100644 --- a/lib/ui/user/edit/user_edit_vm.dart +++ b/lib/ui/user/edit/user_edit_vm.dart @@ -71,16 +71,12 @@ class UserEditVM { }, onSavePressed: (BuildContext context) { final Completer completer = new Completer(); - if (state.authState.hasRecentlyEnteredPassword) { - store.dispatch(SaveUserRequest(completer: completer, user: user)); - } else { - passwordCallback( - context: context, - callback: (password) { - store.dispatch(SaveUserRequest( - completer: completer, user: user, password: password)); - }); - } + passwordCallback( + context: context, + callback: (password) { + store.dispatch(SaveUserRequest( + completer: completer, user: user, password: password)); + }); return completer.future.then((savedUser) { if (isMobile(context)) { store.dispatch(UpdateCurrentRoute(UserViewScreen.route)); diff --git a/lib/utils/dialogs.dart b/lib/utils/dialogs.dart index 5920d414c..20b9f364b 100644 --- a/lib/utils/dialogs.dart +++ b/lib/utils/dialogs.dart @@ -1,5 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_redux/flutter_redux.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/alert_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/forms/save_cancel_buttons.dart'; @@ -62,16 +64,25 @@ void confirmCallback({ ); } -void passwordCallback({BuildContext context, Function(String) callback}) { - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) { - return PasswordConfirmation( - callback: callback, - ); - }, - ); +void passwordCallback({ + BuildContext context, + Function(String) callback, + bool alwaysRequire = false, +}) { + final state = StoreProvider.of(context).state; + if (state.authState.hasRecentlyEnteredPassword && !alwaysRequire) { + callback(null); + } else { + showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return PasswordConfirmation( + callback: callback, + ); + }, + ); + } } class PasswordConfirmation extends StatefulWidget {