diff wiki/signals.py @ 627:a4300639c6e7

Wiki integration. Create task to delete old cookie records. Rework logic upon logout, as session will not be available. Set an attribute on the request instead.
author Brian Neal <bgneal@gmail.com>
date Mon, 12 Nov 2012 15:10:52 -0600
parents a6bc1e2efa63
children f4c043cf55ac
line wrap: on
line diff
--- a/wiki/signals.py	Wed Nov 07 20:17:33 2012 -0600
+++ b/wiki/signals.py	Mon Nov 12 15:10:52 2012 -0600
@@ -5,6 +5,7 @@
 
 from django.contrib.auth.signals import user_logged_in, user_logged_out
 
+from wiki.constants import SESSION_SET_FLAG, SESSION_SET_MEMBER
 
 logger = logging.getLogger(__name__)
 
@@ -17,7 +18,7 @@
     """
     logger.info('User login: %s', user.username)
 
-    request.session['wiki_set_cookie'] = True
+    request.session[SESSION_SET_FLAG] = True
 
 
 def logout_callback(sender, request, user, **kwargs):
@@ -25,10 +26,16 @@
 
     Sets a flag for the middleware to delete the external cookie.
 
+    Since the user is about to logout, her session will be wiped out after
+    this function returns. This forces us to set an attribute on the request
+    object so that the response middleware can delete the wiki's cookie.
+
     """
     logger.info('User logout: %s', user.username)
 
-    request.session['wiki_delete_cookie'] = True
+    # Remember what Redis set member to delete by adding an attribute to the
+    # request object:
+    request.wiki_delete_cookie = request.session.get(SESSION_SET_MEMBER)
 
 
 user_logged_in.connect(login_callback, dispatch_uid='wiki.signals.login')