Handle '__setauthcookie'
authorChristophe de Vienne <christophe@unlish.com>
Thu, 18 Sep 2014 16:51:55 +0200
changeset 11509 ca3412269cd1
parent 11508 ef8b9021b47b
child 11510 2e52647af650
Handle '__setauthcookie' '__setauthcookie' is a form parameter added by the 'rememberme' cube. If present and equals to '1', the cookie max_age will be set to 7 days instead of being a session cookie. To make sure the auth cookie is renewed, the reissue_time is set to 1h.
pyramid_cubicweb/defaults.py
pyramid_cubicweb/login.py
--- a/pyramid_cubicweb/defaults.py	Thu Sep 18 15:07:02 2014 +0200
+++ b/pyramid_cubicweb/defaults.py	Thu Sep 18 16:51:55 2014 +0200
@@ -28,7 +28,8 @@
 
     config.set_authentication_policy(
         AuthTktAuthenticationPolicy(
-            secret, callback=get_principals, hashalg='sha512'))
+            secret, callback=get_principals, hashalg='sha512',
+            reissue_time=3600))
     config.set_authorization_policy(ACLAuthorizationPolicy())
 
     config.include('pyramid_cubicweb.login')
--- a/pyramid_cubicweb/login.py	Thu Sep 18 15:07:02 2014 +0200
+++ b/pyramid_cubicweb/login.py	Thu Sep 18 16:51:55 2014 +0200
@@ -33,7 +33,10 @@
         del request.cw_request.post['__password']
         return login_form(request)
 
-    headers = security.remember(request, user_eid)
+    max_age = None
+    if request.params.get('__setauthcookie') == '1':
+        max_age = '604800'
+    headers = security.remember(request, user_eid, max_age=max_age)
 
     new_path = request.params.get('postlogin_path', '/')