Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
626:a6bc1e2efa63 | 627:a4300639c6e7 |
---|---|
3 """ | 3 """ |
4 import logging | 4 import logging |
5 | 5 |
6 from django.contrib.auth.signals import user_logged_in, user_logged_out | 6 from django.contrib.auth.signals import user_logged_in, user_logged_out |
7 | 7 |
8 from wiki.constants import SESSION_SET_FLAG, SESSION_SET_MEMBER | |
8 | 9 |
9 logger = logging.getLogger(__name__) | 10 logger = logging.getLogger(__name__) |
10 | 11 |
11 | 12 |
12 def login_callback(sender, request, user, **kwargs): | 13 def login_callback(sender, request, user, **kwargs): |
15 Sets a flag for the middleware to create an external cookie. | 16 Sets a flag for the middleware to create an external cookie. |
16 | 17 |
17 """ | 18 """ |
18 logger.info('User login: %s', user.username) | 19 logger.info('User login: %s', user.username) |
19 | 20 |
20 request.session['wiki_set_cookie'] = True | 21 request.session[SESSION_SET_FLAG] = True |
21 | 22 |
22 | 23 |
23 def logout_callback(sender, request, user, **kwargs): | 24 def logout_callback(sender, request, user, **kwargs): |
24 """Signal callback function for a user logging in. | 25 """Signal callback function for a user logging in. |
25 | 26 |
26 Sets a flag for the middleware to delete the external cookie. | 27 Sets a flag for the middleware to delete the external cookie. |
27 | 28 |
29 Since the user is about to logout, her session will be wiped out after | |
30 this function returns. This forces us to set an attribute on the request | |
31 object so that the response middleware can delete the wiki's cookie. | |
32 | |
28 """ | 33 """ |
29 logger.info('User logout: %s', user.username) | 34 logger.info('User logout: %s', user.username) |
30 | 35 |
31 request.session['wiki_delete_cookie'] = True | 36 # Remember what Redis set member to delete by adding an attribute to the |
37 # request object: | |
38 request.wiki_delete_cookie = request.session.get(SESSION_SET_MEMBER) | |
32 | 39 |
33 | 40 |
34 user_logged_in.connect(login_callback, dispatch_uid='wiki.signals.login') | 41 user_logged_in.connect(login_callback, dispatch_uid='wiki.signals.login') |
35 user_logged_out.connect(logout_callback, dispatch_uid='wiki.signals.logout') | 42 user_logged_out.connect(logout_callback, dispatch_uid='wiki.signals.logout') |