Skip to content

Commit

Permalink
support backup token authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 29, 2023
1 parent db1bbf4 commit a539aa4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions backend/api/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
include(
[
re_path(
r"^login/(?P<form>email|username|user-id|otp)/$",
r"^login/(?P<form>email|username|user-id|otp|token)/$",
LoginView.as_view(),
name="login",
),
Expand Down
3 changes: 3 additions & 0 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
BaseAuthForm,
EmailAuthForm,
OtpAuthForm,
TokenAuthForm,
UserIdAuthForm,
UsernameAuthForm,
)
Expand All @@ -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).
Expand Down

0 comments on commit a539aa4

Please sign in to comment.