Browse Source

neon: Required setting scheme for login

pull/273/head
jld3103 2 years ago
parent
commit
a74238d3bc
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 12
      packages/neon/neon/lib/src/pages/login.dart
  2. 5
      packages/neon/neon/lib/src/utils/validators.dart

12
packages/neon/neon/lib/src/pages/login.dart

@ -200,18 +200,10 @@ class _LoginPageState extends State<LoginPage> {
), ),
keyboardType: TextInputType.url, keyboardType: TextInputType.url,
initialValue: widget.serverURL, initialValue: widget.serverURL,
validator: (final input) => validateHttpUrl( validator: (final input) => validateHttpUrl(context, input),
context,
input,
allowEmptyScheme: true,
),
onFieldSubmitted: (final input) { onFieldSubmitted: (final input) {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
var url = input; _loginBloc.setServerURL(input);
if (!(url.startsWith('http://') || url.startsWith('https://'))) {
url = 'http://$url';
}
_loginBloc.setServerURL(url);
} else { } else {
_focusNode.requestFocus(); _focusNode.requestFocus();
} }

5
packages/neon/neon/lib/src/utils/validators.dart

@ -4,7 +4,6 @@ String? validateHttpUrl(
final BuildContext context, final BuildContext context,
final String? input, { final String? input, {
final bool httpsOnly = false, final bool httpsOnly = false,
final bool allowEmptyScheme = false,
}) { }) {
if (input == null || input == '') { if (input == null || input == '') {
return AppLocalizations.of(context).errorInvalidURL; return AppLocalizations.of(context).errorInvalidURL;
@ -15,9 +14,7 @@ String? validateHttpUrl(
return null; return null;
} }
if (uri.isScheme('http') && !httpsOnly) { if (uri.isScheme('http') && !httpsOnly) {
return null; // TODO: Maybe make a better error message for http URLs if only https is allowed
}
if (uri.isScheme('') && allowEmptyScheme) {
return null; return null;
} }
} catch (_) {} } catch (_) {}

Loading…
Cancel
Save