comparison wiki/receivers.py @ 923:bd043677d527

Wiki app refactor for Django 1.7.7 upgrade.
author Brian Neal <bgneal@gmail.com>
date Tue, 07 Apr 2015 20:30:25 -0500
parents wiki/signals.py@63603e931503
children
comparison
equal deleted inserted replaced
922:1a832625c047 923:bd043677d527
1 """Signal handlers for wiki integration.
2
3 We are interested in hearing about users logging in and out, so we can create
4 and destroy an external cookie to allow access to the wiki.
5
6 """
7 import logging
8
9 from django.contrib.auth.signals import user_logged_in, user_logged_out
10
11 from wiki.constants import SESSION_SET_MEMBER
12
13 logger = logging.getLogger(__name__)
14
15
16 def login_callback(sender, request, user, **kwargs):
17 """Signal callback function for a user logging in.
18
19 Sets a flag for the middleware to create an external cookie.
20
21 """
22 logger.info('User login: %s', user.username)
23
24 request.wiki_set_cookie = True
25
26
27 def logout_callback(sender, request, user, **kwargs):
28 """Signal callback function for a user logging in.
29
30 Sets a flag for the middleware to delete the external cookie.
31
32 Since the user is about to logout, her session will be wiped out after
33 this function returns. This forces us to set an attribute on the request
34 object so that the response middleware can delete the wiki's cookie.
35
36 """
37 if user:
38 logger.info('User logout: %s', user.username)
39
40 # Remember what Redis set member to delete by adding an attribute to the
41 # request object:
42 request.wiki_delete_cookie = request.session.get(SESSION_SET_MEMBER)
43
44
45 user_logged_in.connect(login_callback, dispatch_uid='wiki.receivers.login')
46 user_logged_out.connect(logout_callback, dispatch_uid='wiki.receivers.logout')