Browse Source

neon: Allow empty scheme for login

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

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

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

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

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

Loading…
Cancel
Save