save “stay_logged_in” in the session
authorJakob Kramer <jakob.kramer@gmx.de>
Wed, 22 May 2013 12:51:12 +0000 (14:51 +0200)
committerRodney Ewing <ewing.rj@gmail.com>
Thu, 11 Jul 2013 21:56:40 +0000 (14:56 -0700)
Since sessions are rebuilt, e.g. when you try to post a blank
comment and therefore receive an error message, the session will
be overwritten without the old max_age.

mediagoblin/auth/views.py
mediagoblin/tools/session.py

index d276a074869b3b5a1ce63b789d1aaaa0c8c6c077..d54762b0cb2f3ff07e6a702e7b72652f00fb1391 100644 (file)
@@ -89,7 +89,7 @@ def login(request):
             if user:
                 # set up login in session
                 if login_form.stay_logged_in.data:
-                    request.session.max_age = 30 * 24 * 60 * 60
+                    request.session['stay_logged_in'] = True
                 request.session['user_id'] = unicode(user.id)
                 request.session.save()
 
index ccf9644381a8359950dfd80ae19d887d692aa115..d79afb66428102ffccac535f4b1740d2aedc4a4e 100644 (file)
@@ -21,10 +21,11 @@ import crypto
 
 _log = logging.getLogger(__name__)
 
+MAX_AGE = 30 * 24 * 60 * 60
+
 class Session(dict):
     def __init__(self, *args, **kwargs):
         self.send_new_cookie = False
-        self.max_age = None
         dict.__init__(self, *args, **kwargs)
 
     def save(self):
@@ -65,5 +66,10 @@ class SessionManager(object):
         elif not session:
             response.delete_cookie(self.cookie_name)
         else:
+            if session.get('stay_logged_in', False):
+                max_age = MAX_AGE
+            else:
+                max_age = None
+
             response.set_cookie(self.cookie_name, self.signer.dumps(session),
-                max_age=session.max_age, httponly=True)
+                max_age=max_age, httponly=True)