This commit is contained in:
parent
aa23decaff
commit
efcb15e2e3
@ -3,7 +3,8 @@ import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:sodium_libs/sodium_libs.dart';
|
||||
import 'package:repertory/models/auth.dart';
|
||||
import 'package:sodium_libs/sodium_libs.dart' show SecureKey, StringX;
|
||||
|
||||
typedef Validator = bool Function(String);
|
||||
|
||||
@ -106,8 +107,8 @@ Map<String, dynamic> createDefaultSettings(String mountType) {
|
||||
return {};
|
||||
}
|
||||
|
||||
void displayAuthError() {
|
||||
if (constants.navigatorKey.currentContext == null) {
|
||||
void displayAuthError(Auth auth) {
|
||||
if (!auth.authenticated || constants.navigatorKey.currentContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,11 @@ class Auth with ChangeNotifier {
|
||||
|
||||
void logoff() {
|
||||
_authenticated = false;
|
||||
_key = SecureKey.random(constants.sodium, 32);
|
||||
_user = "";
|
||||
mountList?.clear();
|
||||
|
||||
notifyListeners();
|
||||
|
||||
mountList?.clear();
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ class Mount with ChangeNotifier {
|
||||
);
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
displayAuthError();
|
||||
displayAuthError(_auth);
|
||||
_auth.logoff();
|
||||
return false;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class MountList with ChangeNotifier {
|
||||
);
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
displayAuthError();
|
||||
displayAuthError(_auth);
|
||||
_auth.logoff();
|
||||
return;
|
||||
}
|
||||
@ -155,7 +155,7 @@ class MountList with ChangeNotifier {
|
||||
ret = true;
|
||||
break;
|
||||
case 401:
|
||||
displayAuthError();
|
||||
displayAuthError(_auth);
|
||||
_auth.logoff();
|
||||
break;
|
||||
case 404:
|
||||
|
@ -106,7 +106,6 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
void dispose() {
|
||||
final settings = getChanged(widget.origSettings, widget.settings);
|
||||
if (settings.isNotEmpty) {
|
||||
debugPrint("start");
|
||||
final key =
|
||||
Provider.of<Auth>(
|
||||
constants.navigatorKey.currentContext!,
|
||||
@ -114,15 +113,13 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
).key;
|
||||
convertAllToString(settings, key)
|
||||
.then((map) async {
|
||||
debugPrint("map");
|
||||
try {
|
||||
final authProvider = Provider.of<Auth>(
|
||||
constants.navigatorKey.currentContext!,
|
||||
listen: false,
|
||||
);
|
||||
final auth = await authProvider.createAuth();
|
||||
|
||||
debugPrint("auth");
|
||||
final auth = await authProvider.createAuth();
|
||||
final response = await http.put(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
@ -132,7 +129,7 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
);
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
displayAuthError();
|
||||
displayAuthError(authProvider);
|
||||
authProvider.logoff();
|
||||
}
|
||||
} catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user