From 6dcc3784cdf9b89b1134562b61517a912316eabf Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 18 Jun 2024 19:26:12 +0200 Subject: [PATCH] django 5.1: support LoginRequiredMiddleware --- mfa/views.py | 7 +++++++ tests/settings.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/mfa/views.py b/mfa/views.py index e4178f7..7ead137 100644 --- a/mfa/views.py +++ b/mfa/views.py @@ -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): @@ -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 diff --git a/tests/settings.py b/tests/settings.py index f938211..ae4cee5 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -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', ]