diff --git a/src/wagtail_2fa/forms.py b/src/wagtail_2fa/forms.py index 4cb5b34..2fcc17b 100644 --- a/src/wagtail_2fa/forms.py +++ b/src/wagtail_2fa/forms.py @@ -1,3 +1,5 @@ +import re + from django import forms from django.contrib.auth import authenticate from django.utils.translation import gettext_lazy as _ @@ -16,6 +18,12 @@ def __init__(self, user, *args, **kwargs): {"autofocus": "autofocus", "autocomplete": "off"} ) + def clean_otp_token(self): + '''Remove whitespace because authentication apps often present token + as "123 456". It is very confusing for user if this exact format + isn't supported.''' + return re.sub(r'\s', '', self.cleaned_data.get('otp_token', '')) + def clean(self): self.clean_otp(self.user) return self.cleaned_data