Skip to content
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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please provide a unittest

'''Remove whitespace because authentication apps often present token
as "123 456". It is very confusing for user if this exact format
isn't supported.'''
Comment on lines +22 to +24
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'''Remove whitespace because authentication apps often present token
as "123 456". It is very confusing for user if this exact format
isn't supported.'''
"""Removes whitespace to support tokens like '123 456' shown in authentication apps."""

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