add login option: stay_logged_in
authorJakob Kramer <jakob.kramer@gmx.de>
Thu, 9 May 2013 22:40:13 +0000 (00:40 +0200)
committerRodney Ewing <ewing.rj@gmail.com>
Thu, 11 Jul 2013 21:56:40 +0000 (14:56 -0700)
As proposed in issue #354; it adds an attribute max_age
to mediagoblin.tools.session.Session  that is passed to
response.set_cookie;  max_age is set to 30  days if the
checkbox is selected

mediagoblin/auth/views.py
mediagoblin/plugins/basic_auth/forms.py
mediagoblin/tools/session.py

index 1cff8dcc5b149b0ba904098dddd34a5fb430091d..d276a074869b3b5a1ce63b789d1aaaa0c8c6c077 100644 (file)
@@ -88,6 +88,8 @@ 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['user_id'] = unicode(user.id)
                 request.session.save()
 
index 72d99dffaf8519c6446fc84d5badb7d642fc9360..0793f5f43f17779c8ba5c08fe48dd55d39707d9e 100644 (file)
@@ -41,3 +41,5 @@ class LoginForm(wtforms.Form):
          normalize_user_or_email_field()])
     password = wtforms.PasswordField(
         _('Password'))
+    stay_logged_in = wtforms.BooleanField(
+        _('Stay logged in'))
index fdc32523c8acdcb46ba7166d48d6fa0918510825..ccf9644381a8359950dfd80ae19d887d692aa115 100644 (file)
@@ -24,6 +24,7 @@ _log = logging.getLogger(__name__)
 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,4 +66,4 @@ class SessionManager(object):
             response.delete_cookie(self.cookie_name)
         else:
             response.set_cookie(self.cookie_name, self.signer.dumps(session),
-                httponly=True)
+                max_age=session.max_age, httponly=True)