-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(neon_framework): Enable user password confirmation
Signed-off-by: provokateurin <[email protected]>
- Loading branch information
1 parent
e9233c4
commit 68b75c8
Showing
9 changed files
with
369 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ unfocus | |
writeln | ||
xmark | ||
arrowshape | ||
autocorrect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/neon_framework/lib/src/utils/password_confirmation.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:neon_framework/models.dart'; | ||
import 'package:neon_framework/src/widgets/dialog.dart'; | ||
import 'package:neon_framework/utils.dart'; | ||
|
||
/// For testing using `MockAccount` is just fine because each of them will have a different hashCode and will not interfere with existing state. | ||
Map<Account, DateTime> _lastPasswordConfirmations = {}; | ||
|
||
/// Confirms the user password if necessary. | ||
/// | ||
/// Returns `true` if not necessary or successful. | ||
/// Returns `false` if the user aborted or it was unsuccessful. | ||
Future<bool> confirmPassword( | ||
BuildContext context, { | ||
@visibleForTesting DateTime? now, | ||
}) async { | ||
final account = NeonProvider.of<Account>(context); | ||
final lastConfirmation = _lastPasswordConfirmations[account]; | ||
if (lastConfirmation != null && (now ?? DateTime.now()).difference(lastConfirmation) < const Duration(minutes: 30)) { | ||
return true; | ||
} | ||
|
||
final result = await showAdaptiveDialog<bool?>( | ||
context: context, | ||
builder: (context) => NeonPasswordConfirmationDialog( | ||
account: account, | ||
), | ||
); | ||
|
||
if (result == null || !result) { | ||
return false; | ||
} | ||
|
||
_lastPasswordConfirmations[account] = now ?? DateTime.now(); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.