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;
|
bool get authenticated => _authenticated;
|
||||||
SecureKey get key => _key;
|
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 sodium = constants.sodium;
|
||||||
|
|
||||||
final keyHash = sodium.crypto.genericHash(
|
final keyHash = sodium.crypto.genericHash(
|
||||||
@@ -25,11 +26,28 @@ class Auth with ChangeNotifier {
|
|||||||
message: Uint8List.fromList(password.toCharArray()),
|
message: Uint8List.fromList(password.toCharArray()),
|
||||||
);
|
);
|
||||||
|
|
||||||
_authenticated = true;
|
|
||||||
_key = SecureKey.fromList(sodium, keyHash);
|
_key = SecureKey.fromList(sodium, keyHash);
|
||||||
_user = user;
|
_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();
|
notifyListeners();
|
||||||
|
|
||||||
|
return _authenticated;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
|
|
||||||
|
logoff();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> createAuth() async {
|
Future<String> createAuth() async {
|
||||||
|
@@ -57,22 +57,26 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setState(() => _enabled = false);
|
setState(() => _enabled = false);
|
||||||
await auth.authenticate(
|
var authenticated = await auth.authenticate(
|
||||||
_userController.text.trim(),
|
_userController.text.trim(),
|
||||||
_passwordController.text,
|
_passwordController.text,
|
||||||
);
|
);
|
||||||
setState(() => _enabled = true);
|
setState(() => _enabled = true);
|
||||||
|
|
||||||
// if (!mounted) return;
|
if (authenticated) {
|
||||||
//
|
return;
|
||||||
// if (!(ok == true || auth.authenticated)) {
|
}
|
||||||
// ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
// const SnackBar(
|
if (!context.mounted) {
|
||||||
// content: Text('Invalid username or password'),
|
return;
|
||||||
// behavior: SnackBarBehavior.floating,
|
}
|
||||||
// ),
|
|
||||||
// );
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
// }
|
const SnackBar(
|
||||||
|
content: Text('Invalid username or password'),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void navigateHomePostFrame() {
|
void navigateHomePostFrame() {
|
||||||
|
Reference in New Issue
Block a user