Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean whitespace from token #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wagtail_2fa/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from django import forms
from django.contrib.auth import authenticate
from django.utils.translation import gettext_lazy as _
Expand All @@ -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
Expand Down