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