We should always have a request.user object, even if None.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 3 Apr 2011 23:35:52 +0000 (18:35 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 3 Apr 2011 23:35:52 +0000 (18:35 -0500)
mediagoblin/util.py

index 5a56d432e3d2e59dbe2899032f8b182276d4511f..fe77a0d9450a9ed49c6230e1f34833414fbcc1d8 100644 (file)
@@ -36,12 +36,12 @@ def setup_user_in_request(request):
     if not request.session.has_key('user_id'):
         return
 
+    user = None
+
     try:
         user = request.db.User.one({'_id': request.session['user_id']})
         
-        if user:
-            request.user = user
-        else:
+        if not user:
             # Something's wrong... this user doesn't exist?  Invalidate
             # this session.
             request.session.invalidate()
@@ -50,3 +50,5 @@ def setup_user_in_request(request):
         # Something's wrong... we shouldn't have multiple users with
         # the same user id.  Invalidate this session.
         request.session.invalidate()
+
+    request.user = user