Skip to content

Commit 6dcc378

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

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-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

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
'mfa.middleware.MFAEnforceMiddleware',
2222
]
2323

24+
if django.VERSION >= (5, 1):
25+
MIDDLEWARE.append('django.contrib.auth.middleware.LoginRequiredMiddleware')
26+
2427
AUTHENTICATION_BACKENDS = [
2528
'django.contrib.auth.backends.ModelBackend',
2629
]

0 commit comments

Comments
 (0)