]> git.openstreetmap.org Git - osqa.git/blob - forum/middleware/extended_user.py
Merging jambazov --> trunk.
[osqa.git] / forum / middleware / extended_user.py
1 from django.contrib.auth.middleware import AuthenticationMiddleware\r
2 from django.contrib.auth import logout\r
3 from forum.models.user import AnonymousUser\r
4 from forum.views.auth import forward_suspended_user\r
5 import logging\r
6 \r
7 class ExtendedUser(AuthenticationMiddleware):\r
8     def process_request(self, request):\r
9         super(ExtendedUser, self).process_request(request)\r
10         if request.user.is_authenticated():\r
11             try:\r
12                 request.user = request.user.user\r
13 \r
14                 if request.user.is_suspended():\r
15                     user = request.user\r
16                     logout(request)\r
17                     return forward_suspended_user(request, user)\r
18 \r
19                 return None\r
20             except Exception, e:\r
21                 import traceback\r
22                 logging.error("Unable to convert auth_user %s to forum_user: \n%s" % (\r
23                     request.user.id, traceback.format_exc()\r
24                 ))\r
25 \r
26         request.user = AnonymousUser()\r
27         return None