X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/1a949f7c97dc2f34c135f5cdf088df2927d3d652..df656ce4c8ae86e0be20cc6e497cbab1ae8ffb3b:/forum/middleware/extended_user.py?ds=sidebyside diff --git a/forum/middleware/extended_user.py b/forum/middleware/extended_user.py index e54c9b4..ca1d151 100644 --- a/forum/middleware/extended_user.py +++ b/forum/middleware/extended_user.py @@ -1,15 +1,27 @@ -from django.contrib.auth.middleware import AuthenticationMiddleware -from forum.models.user import AnonymousUser - -class ExtendedUser(AuthenticationMiddleware): - def process_request(self, request): - super(ExtendedUser, self).process_request(request) - if request.user.is_authenticated(): - try: - request.user = request.user.user - return None - except: - pass - - request.user = AnonymousUser() +from django.contrib.auth.middleware import AuthenticationMiddleware +from django.contrib.auth import logout +from forum.models.user import AnonymousUser +from forum.views.auth import forward_suspended_user +import logging + +class ExtendedUser(AuthenticationMiddleware): + def process_request(self, request): + super(ExtendedUser, self).process_request(request) + if request.user.is_authenticated(): + try: + request.user = request.user.user + + if request.user.is_suspended(): + user = request.user + logout(request) + return forward_suspended_user(request, user) + + return None + except Exception, e: + import traceback + logging.error("Unable to convert auth_user %s to forum_user: \n%s" % ( + request.user.id, traceback.format_exc() + )) + + request.user = AnonymousUser() return None \ No newline at end of file