Browse Source

Merge pull request #244 from provokateurin/feature/allow-empty-scheme-login

neon: Allow empty scheme for login
pull/249/head
Kate 2 years ago committed by GitHub
parent
commit
bfb5187d93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/neon/lib/src/pages/login.dart
  2. 18
      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();
}

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

@ -4,20 +4,24 @@ 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;
}
return null;
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) {

Loading…
Cancel
Save