From 35ff03dfce110298a20c2ce6c6123d50bb2da8f3 Mon Sep 17 00:00:00 2001 From: Felipe Lessa Date: Mon, 25 May 2015 18:57:45 -0300 Subject: [PATCH] Add timeouts to State, not implemented yet. --- .../src/Web/ServerSession/Frontend/Yesod.hs | 9 +++- .../ServerSession/Frontend/Yesod/Internal.hs | 2 + serversession/src/Web/ServerSession/Core.hs | 6 ++- .../src/Web/ServerSession/Core/Internal.hs | 41 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod.hs b/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod.hs index cbb5dd8..679979b 100644 --- a/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod.hs +++ b/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod.hs @@ -1,3 +1,4 @@ +-- | Yesod server-side session support. module Web.ServerSession.Frontend.Yesod ( -- * Using server-side sessions simpleBackend @@ -5,7 +6,13 @@ module Web.ServerSession.Frontend.Yesod -- * Invalidating session IDs , forceInvalidate , ForceInvalidate(..) + -- * State configuration + , setCookieName + , setAuthKey + , setIdleTimeout + , setAbsoluteTimeout + , State ) where -import Web.ServerSession.Core (ForceInvalidate(..)) +import Web.ServerSession.Core import Web.ServerSession.Frontend.Yesod.Internal diff --git a/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod/Internal.hs b/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod/Internal.hs index 4290fa2..50f9240 100644 --- a/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod/Internal.hs +++ b/serversession-frontend-yesod/src/Web/ServerSession/Frontend/Yesod/Internal.hs @@ -1,3 +1,5 @@ +-- | Internal module exposing the guts of the package. Use at +-- your own risk. No API stability guarantees apply. module Web.ServerSession.Frontend.Yesod.Internal ( simpleBackend , backend diff --git a/serversession/src/Web/ServerSession/Core.hs b/serversession/src/Web/ServerSession/Core.hs index 163b80d..1a55565 100644 --- a/serversession/src/Web/ServerSession/Core.hs +++ b/serversession/src/Web/ServerSession/Core.hs @@ -7,15 +7,17 @@ module Web.ServerSession.Core -- * For serversession frontends , SessionMap - , State(..) + , State , createState - , setAuthKey , loadSession , saveSession , SaveSessionToken , forceInvalidateKey -- ** To be re-exported by frontends , setCookieName + , setAuthKey + , setIdleTimeout + , setAbsoluteTimeout , ForceInvalidate(..) ) where diff --git a/serversession/src/Web/ServerSession/Core/Internal.hs b/serversession/src/Web/ServerSession/Core/Internal.hs index ec6115b..823dbc5 100644 --- a/serversession/src/Web/ServerSession/Core/Internal.hs +++ b/serversession/src/Web/ServerSession/Core/Internal.hs @@ -13,6 +13,8 @@ module Web.ServerSession.Core.Internal , createState , setCookieName , setAuthKey + , setIdleTimeout + , setAbsoluteTimeout , loadSession , saveSession , SaveSessionToken(..) @@ -206,6 +208,45 @@ setAuthKey :: Text -> State s -> State s setAuthKey val state = state { authKey = val } +-- | Set the idle timeout for all sessions. This is used both on +-- the client side (by setting the cookie expires fields) and on +-- the server side (the idle timeout is enforced even if the +-- cookie expiration is ignored). Setting to @Nothing@ removes +-- the idle timeout entirely. +-- +-- \"[The idle timemout] defines the amount of time a session +-- will remain active in case there is no activity in the +-- session, closing and invalidating the session upon the defined +-- idle period since the last HTTP request received by the web +-- application for a given session ID.\" +-- () +-- +-- Defaults to 7 days. +setIdleTimeout :: Maybe DiffTime -> State s -> State s +setIdleTimeout (Just d) _ | d <= 0 = error "serversession/setIdleTimeout: Timeout should be positive." +setIdleTimeout val state = state { idleTimeout = val } + + +-- | Set the absolute timeout for all sessions. This is used both on +-- the client side (by setting the cookie expires fields) and on +-- the server side (the absolute timeout is enforced even if the +-- cookie expiration is ignored). Setting to @Nothing@ removes +-- the absolute timeout entirely. +-- +-- \"[The absolute timeout] defines the maximum amount of time a +-- session can be active, closing and invalidating the session +-- upon the defined absolute period since the given session was +-- initially created by the web application. After invalidating +-- the session, the user is forced to (re)authenticate again in +-- the web application and establish a new session.\" +-- () +-- +-- Defaults to 60 days. +setAbsoluteTimeout :: Maybe DiffTime -> State s -> State s +setAbsoluteTimeout (Just d) _ | d <= 0 = error "serversession/setAbsoluteTimeout: Timeout should be positive." +setAbsoluteTimeout val state = state { absoluteTimeout = val } + + -- | Load the session map from the storage backend. The value of -- the session cookie should be given as argument if present. --