handle authentication failure in auth screen
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
@@ -17,7 +17,8 @@ class Auth with ChangeNotifier {
|
||||
bool get authenticated => _authenticated;
|
||||
SecureKey get key => _key;
|
||||
|
||||
Future<void> authenticate(String user, String password) async {
|
||||
Future<bool> authenticate(String user, String password) async {
|
||||
try {
|
||||
final sodium = constants.sodium;
|
||||
|
||||
final keyHash = sodium.crypto.genericHash(
|
||||
@@ -25,11 +26,28 @@ class Auth with ChangeNotifier {
|
||||
message: Uint8List.fromList(password.toCharArray()),
|
||||
);
|
||||
|
||||
_authenticated = true;
|
||||
_key = SecureKey.fromList(sodium, keyHash);
|
||||
_user = user;
|
||||
|
||||
final auth = await createAuth();
|
||||
final response = await http.put(
|
||||
Uri.parse(
|
||||
Uri.encodeFull('${getBaseUri()}/api/v1/locations?auth=$auth'),
|
||||
),
|
||||
);
|
||||
|
||||
_authenticated = (response.statusCode == 200);
|
||||
if (_authenticated) {
|
||||
notifyListeners();
|
||||
|
||||
return _authenticated;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
}
|
||||
|
||||
logoff();
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<String> createAuth() async {
|
||||
|
@@ -57,22 +57,26 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
}
|
||||
|
||||
setState(() => _enabled = false);
|
||||
await auth.authenticate(
|
||||
var authenticated = await auth.authenticate(
|
||||
_userController.text.trim(),
|
||||
_passwordController.text,
|
||||
);
|
||||
setState(() => _enabled = true);
|
||||
|
||||
// if (!mounted) return;
|
||||
//
|
||||
// if (!(ok == true || auth.authenticated)) {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// const SnackBar(
|
||||
// content: Text('Invalid username or password'),
|
||||
// behavior: SnackBarBehavior.floating,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
if (authenticated) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Invalid username or password'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void navigateHomePostFrame() {
|
||||
|
Reference in New Issue
Block a user