From e01e9c6fbd3e76aeef643afa36b5ab52d2f03b09 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 12 May 2021 21:10:25 +0300 Subject: Fix middleware --- servo/lib/middleware.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/servo/lib/middleware.py b/servo/lib/middleware.py index 6549e6a..6eadead 100644 --- a/servo/lib/middleware.py +++ b/servo/lib/middleware.py @@ -25,17 +25,18 @@ class LoginRequiredMiddleware: self.get_response = get_response def __call__(self, request): - response = self.get_response(request) - assert hasattr(request, 'user'), "The Login Required middleware\ requires authentication middleware to be installed. Edit your\ - MIDDLEWARE_CLASSES setting to insert\ + MIDDLEWARE setting to insert\ 'django.contrib.auth.middlware.AuthenticationMiddleware'. If that doesn't\ work, ensure your TEMPLATE_CONTEXT_PROCESSORS setting includes\ 'django.core.context_processors.auth'." - if request.user.is_authenticated == False: + + response = self.get_response(request) + + if not request.user.is_authenticated: path = request.path_info.lstrip('/') - if any(m.match(path) for m in EXEMPT_URLS) == False: + if not any(m.match(path) for m in EXEMPT_URLS): return HttpResponseRedirect(settings.LOGIN_URL) return response -- cgit v1.2.3