Compare commits
No commits in common. "a28151068a06fbfe4c4b47167beabf867e19052b" and "225a5cedc57c63c2d63c643044573ff14ce1426c" have entirely different histories.
a28151068a
...
225a5cedc5
@ -12,10 +12,6 @@ class NullPasswordException implements Exception {
|
|||||||
String error() => 'password cannot be null';
|
String error() => 'password cannot be null';
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthenticationFailedException implements Exception {
|
|
||||||
String error() => 'failed to authenticate user';
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore: prefer_function_declarations_over_variables
|
// ignore: prefer_function_declarations_over_variables
|
||||||
final Validator noRestrictedChars = (value) {
|
final Validator noRestrictedChars = (value) {
|
||||||
return [
|
return [
|
||||||
@ -237,43 +233,29 @@ bool validateSettings(
|
|||||||
Future<Map<String, dynamic>> convertAllToString(
|
Future<Map<String, dynamic>> convertAllToString(
|
||||||
Map<String, dynamic> settings,
|
Map<String, dynamic> settings,
|
||||||
) async {
|
) async {
|
||||||
String? password;
|
final password = await promptPassword();
|
||||||
Future<Map<String, dynamic>> convert(Map<String, dynamic> settings) async {
|
if (password == null) {
|
||||||
for (var entry in settings.entries) {
|
throw NullPasswordException();
|
||||||
if (entry.value is Map<String, dynamic>) {
|
|
||||||
await convert(entry.value);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.key == 'ApiPassword' ||
|
|
||||||
entry.key == 'EncryptionToken' ||
|
|
||||||
entry.key == 'SecretKey') {
|
|
||||||
if (entry.value.isEmpty) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password == null) {
|
|
||||||
password = await promptPassword();
|
|
||||||
if (password == null) {
|
|
||||||
throw NullPasswordException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
settings[entry.key] = encryptValue(entry.value, password!);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.value is String) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
settings[entry.key] = entry.value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return convert(settings);
|
settings.forEach((key, value) {
|
||||||
|
if (value is Map<String, dynamic>) {
|
||||||
|
convertAllToString(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == 'ApiPassword' ||
|
||||||
|
key == 'EncryptionToken' ||
|
||||||
|
key == 'SecretKey') {
|
||||||
|
value = encryptValue(value, password);
|
||||||
|
} else if (value is String) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings[key] = value.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
String encryptValue(String value, String password) {
|
String encryptValue(String value, String password) {
|
||||||
|
@ -3,12 +3,9 @@ import 'dart:convert' show jsonEncode;
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:repertory/constants.dart' as constants;
|
|
||||||
import 'package:repertory/helpers.dart'
|
import 'package:repertory/helpers.dart'
|
||||||
show
|
show
|
||||||
AuthenticationFailedException,
|
|
||||||
convertAllToString,
|
convertAllToString,
|
||||||
displayErrorMessage,
|
|
||||||
getBaseUri,
|
getBaseUri,
|
||||||
getSettingDescription,
|
getSettingDescription,
|
||||||
getSettingValidators,
|
getSettingValidators,
|
||||||
@ -107,36 +104,22 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
|
|||||||
widget.settings,
|
widget.settings,
|
||||||
widget.origSettings,
|
widget.origSettings,
|
||||||
)) {
|
)) {
|
||||||
displayAuthError() {
|
|
||||||
if (constants.navigatorKey.currentContext != null) {
|
|
||||||
displayErrorMessage(
|
|
||||||
constants.navigatorKey.currentContext!,
|
|
||||||
"Authentication failed",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
convertAllToString(widget.settings)
|
convertAllToString(widget.settings)
|
||||||
.then((map) async {
|
.then((map) async {
|
||||||
try {
|
try {
|
||||||
final response = await http.put(
|
await http.put(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
'${getBaseUri()}/api/v1/settings?data=${jsonEncode(map)}',
|
'${getBaseUri()}/api/v1/settings?data=${jsonEncode(map)}',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 500) {
|
|
||||||
displayAuthError();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('$e');
|
debugPrint('$e');
|
||||||
displayAuthError();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catchError((e) {
|
.catchError((e) {
|
||||||
debugPrint('$e');
|
debugPrint('$e');
|
||||||
displayAuthError();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user