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