From 8ea78390ee3a8d5f3b02574ed96d29111c09d76f Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Wed, 7 Oct 2015 23:17:06 +0200 Subject: [PATCH] Middleware for AJAX requests --- mamweb/middleware.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mamweb/middleware.py b/mamweb/middleware.py index be4efce9..c1014257 100644 --- a/mamweb/middleware.py +++ b/mamweb/middleware.py @@ -40,7 +40,11 @@ class LoggedInHintCookieMiddleware(object): def process_response(self, request, response): if request.is_secure(): # assuming full session info (as the conn. is secure) - if request.user.is_authenticated(): + try: + user = request.user + except AttributeError: # no user - ajax or other special request + return response + if user.is_authenticated(): if not self.cookie_correct(request): expiry = None if request.session.get_expire_at_browser_close() else request.session.get_expiry_date() response.set_cookie(self.cookie_name, value=self.cookie_value, expires=expiry, secure=False)