From a539aa43444aa629ab320c4f4e01933fb0c9c1bb Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 29 Sep 2023 14:11:36 +0100 Subject: [PATCH] support backup token authentication --- backend/api/forms.py | 7 +++++++ backend/api/urls.py | 2 +- backend/api/views.py | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/api/forms.py b/backend/api/forms.py index e6cb0b1..85a7db3 100644 --- a/backend/api/forms.py +++ b/backend/api/forms.py @@ -63,6 +63,13 @@ def get_invalid_login_error_message(self): ) +class TokenAuthForm(BaseAuthForm): + token = forms.CharField(min_length=8, max_length=8) + + def get_invalid_login_error_message(self): + return "Must be exactly 8 characters. A token can only be used once." + + class UsernameAuthForm(BaseAuthForm): username = UsernameField() password = forms.CharField(strip=False) diff --git a/backend/api/urls.py b/backend/api/urls.py index 8113e66..5619bd5 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -8,7 +8,7 @@ include( [ re_path( - r"^login/(?P
email|username|user-id|otp)/$", + r"^login/(?Pemail|username|user-id|otp|token)/$", LoginView.as_view(), name="login", ), diff --git a/backend/api/views.py b/backend/api/views.py index 0dd6a2c..6cd9e13 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -16,6 +16,7 @@ BaseAuthForm, EmailAuthForm, OtpAuthForm, + TokenAuthForm, UserIdAuthForm, UsernameAuthForm, ) @@ -35,6 +36,8 @@ def get_form_class(self): return UserIdAuthForm elif form == "otp": return OtpAuthForm + elif form == "token": + return TokenAuthForm def form_valid(self, form: BaseAuthForm): # Create session (without data).