Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored February 27, 2006

Showing 1 changed file with 13 additions and 0 deletions. Show diff stats Hide diff stats

  1. 13  django/contrib/auth/middleware.py
13  django/contrib/auth/middleware.py
... ...
@@ -0,0 +1,13 @@
  1
+class RequestUserMiddleware:
  2
+    def process_request(self, request):
  3
+        from django.contrib.auth.models import User, SESSION_KEY
  4
+        try:
  5
+            user_id = request.session[SESSION_KEY]
  6
+            if not user_id:
  7
+                raise ValueError
  8
+            user = User.objects.get(pk=user_id)
  9
+        except (AttributeError, KeyError, ValueError, User.DoesNotExist):
  10
+            from django.parts.auth import anonymoususers
  11
+            user = anonymoususers.AnonymousUser()
  12
+        request.user = user
  13
+        return None

0 notes on commit 50f1717

Please sign in to comment.
Something went wrong with that request. Please try again.