changeset 50:328a429dfedb

renew
author Adam Chlipala <adam@chlipala.net>
date Sun, 24 Jul 2011 10:23:50 -0400
parents ba203b170476
children a984dc1c8954
files src/ur/openidUser.ur src/ur/openidUser.urs
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ur/openidUser.ur	Tue Jul 19 09:27:10 2011 -0400
+++ b/src/ur/openidUser.ur	Sun Jul 24 10:23:50 2011 -0400
@@ -90,7 +90,7 @@
             else
                 currentUrl
 
-    val current =
+    fun current' tweakSession =
         login <- getCookie auth;
         case login of
             Some (LoggedIn login) =>
@@ -107,11 +107,20 @@
                                     WHERE identity.User = {[login.User]}
                                       AND identity.Identifier = {[ident]});
                  if valid then
+                     tweakSession login.Session;
                      return (Some login.User)
                  else
                      error <xml>Session not authorized to act as user</xml>)
           | _ => return None
 
+    val current = current' (fn _ => return ())
+
+    val renew = current' (fn id =>
+                             now <- now;
+                             dml (UPDATE session
+                                  SET Expires = {[addSeconds now M.sessionLifetime]}
+                                  WHERE Id = {[id]}))
+
     fun validUser s = String.length s > 0 && String.length s < 20
                       && String.all Char.isAlnum s
 
--- a/src/ur/openidUser.urs	Tue Jul 19 09:27:10 2011 -0400
+++ b/src/ur/openidUser.urs	Sun Jul 24 10:23:50 2011 -0400
@@ -105,6 +105,10 @@
     val current : transaction (option user)
     (* Figure out which, if any, user is logged in on this connection. *)
 
+    val renew : transaction (option user)
+    (* Like [current], but also resets the expiration time of the user's
+     * session, if one is found. *)
+
 
     val main : (string -> xbody -> transaction page) -> transaction {Status : xbody,
                                                                      Other : {Url : url, Xml : xbody}}