_progressModel
..inProgress = true
..message = 'Connection test...';
- _originController.text =
- '${userModel.origin?.host}:${userModel.origin?.port}';
+ _originController.text = userModel.origin?.toString() ?? '';
_accessDomains = _getAccessDomains();
_usernameController.text = userModel.username!;
if (widget.ticket!.isNotEmpty && userModel.activeSession) {
if (value == null || value.isEmpty) {
return 'Please enter origin';
}
- if (value.startsWith('https://') ||
- value.startsWith('http://')) {
- return 'Do not prefix with scheme';
- }
try {
- Uri.https(value, '');
+ normalizeUrl(value);
return null;
} on FormatException catch (_) {
return 'Invalid URI';
+ } on Exception catch (e) {
+ return 'Invalid URI: $e';
}
},
usernameController: _usernameController,
final settings = await ProxmoxGeneralSettingsModel.fromLocalStorage();
//cleaned form fields
- final origin = Uri.https(_originController.text.trim(), '');
+ final origin = normalizeUrl(_originController.text.trim());
final username = _usernameController.text.trim();
final password =
ticket.isNotEmpty ? ticket : _passwordController.text.trim();
..message = 'Connection test...';
});
var host = _originController.text.trim();
- var apiBaseUrl = Uri.https(host, '');
+ var apiBaseUrl = normalizeUrl(host);
RegExp portRE = new RegExp(r":\d{1,5}$");
);
}
}
+
+Uri normalizeUrl(String urlText) {
+ if (urlText.startsWith('https://')) {
+ urlText = urlText.substring('https://'.length);
+ }
+ if (urlText.startsWith('http://')) {
+ throw new Exception("HTTP without TLS is not supported");
+ }
+
+ return Uri.https(urlText, '');
+}