Skip to content

Commit

Permalink
django 5.1: support LoginRequiredMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
xi committed Jun 18, 2024
1 parent 072e8db commit 6dcc378
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mfa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
def stronghold_public(view_func):
return view_func

try:
from django.contrib.auth.decorators import login_not_required
except ImportError:
def login_not_required(view_func):
return view_func


class LoginView(DjangoLoginView):
def no_key_exists(self, form):
Expand Down Expand Up @@ -90,6 +96,7 @@ def form_valid(self, form):
return super().form_valid(form)


@method_decorator(login_not_required, name='dispatch')
@method_decorator(stronghold_public, name='dispatch')
class MFAAuthView(MFAFormView):
form_class = MFAAuthForm
Expand Down
3 changes: 3 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
'mfa.middleware.MFAEnforceMiddleware',
]

if django.VERSION >= (5, 1):
MIDDLEWARE.append('django.contrib.auth.middleware.LoginRequiredMiddleware')

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
]
Expand Down

0 comments on commit 6dcc378

Please sign in to comment.