]> git.openstreetmap.org Git - osqa.git/blob - forum/middleware/extended_user.py
0e44f736e2671b7cccf563e30c8ed54c1ec41e46
[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 \r
6 class ExtendedUser(AuthenticationMiddleware):\r
7     def process_request(self, request):\r
8         super(ExtendedUser, self).process_request(request)\r
9         if request.user.is_authenticated():\r
10             try:\r
11                 request.user = request.user.user\r
12 \r
13                 if request.user.is_suspended():\r
14                     user = request.user\r
15                     logout(request)\r
16                     return forward_suspended_user(request, user)\r
17 \r
18                 return None\r
19             except:\r
20                 pass\r
21 \r
22         request.user = AnonymousUser()\r
23         return None