Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 50f1717525cfa3690e1cdf15869608f7a2bf2884 1 parent 9cdd49c
Joseph Kocherhans jkocherhans authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 django/contrib/auth/middleware.py
13 django/contrib/auth/middleware.py
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.