Skip to content

Commit b495f7a

Browse files
committed
django 5.1: support LoginRequiredMiddleware
1 parent 072e8db commit b495f7a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mfa/views.py

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
def stronghold_public(view_func):
2828
return view_func
2929

30+
try:
31+
from django.contrib.auth.decorators import login_not_required
32+
except ImportError:
33+
def login_not_required(view_func):
34+
return view_func
35+
3036

3137
class LoginView(DjangoLoginView):
3238
def no_key_exists(self, form):
@@ -90,6 +96,7 @@ def form_valid(self, form):
9096
return super().form_valid(form)
9197

9298

99+
@method_decorator(login_not_required, name='dispatch')
93100
@method_decorator(stronghold_public, name='dispatch')
94101
class MFAAuthView(MFAFormView):
95102
form_class = MFAAuthForm

tests/settings.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
22

3+
import django
4+
35
DATABASES = {
46
'default': {
57
'ENGINE': 'django.db.backends.sqlite3',
@@ -21,6 +23,9 @@
2123
'mfa.middleware.MFAEnforceMiddleware',
2224
]
2325

26+
if django.VERSION >= (5, 1):
27+
MIDDLEWARE.append('django.contrib.auth.middleware.LoginRequiredMiddleware')
28+
2429
AUTHENTICATION_BACKENDS = [
2530
'django.contrib.auth.backends.ModelBackend',
2631
]

0 commit comments

Comments
 (0)