magic-removal: added middleware for adding request.user

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2423 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans 2006-02-27 23:03:35 +00:00
parent 9cdd49c1e0
commit 50f1717525
1 changed files with 13 additions and 0 deletions

View File

@ -0,0 +1,13 @@
class RequestUserMiddleware:
def process_request(self, request):
from django.contrib.auth.models import User, SESSION_KEY
try:
user_id = request.session[SESSION_KEY]
if not user_id:
raise ValueError
user = User.objects.get(pk=user_id)
except (AttributeError, KeyError, ValueError, User.DoesNotExist):
from django.parts.auth import anonymoususers
user = anonymoususers.AnonymousUser()
request.user = user
return None