- newtype SessionID = SID {}
- sid :: SessionID :-> Integer
- data Session p = Session {}
- sID :: Session p :-> SessionID
- sStart :: Session p :-> UTCTime
- sLast :: Session p :-> UTCTime
- sExpire :: Session p :-> Integer
- sPayload :: Session p :-> Maybe p
- class (Applicative m, Monad m) => SessionM p m | m -> p where
- prolongSession :: Integer -> m ()
- getSession :: m (Session p)
- putSession :: Session p -> m ()
- delSession :: m ()
- withSession :: (Session p -> Session p) -> m ()
- type SessionMap p = Map SessionID (TVar (Session p))
- newtype Sessions p = Sessions {
- unSessions :: SessionMap p
- withSessions :: (SessionMap p -> SessionMap p) -> Sessions p -> Sessions p
- mkSessions :: Sessions p
- hProlongSession :: forall m q p. (MonadIO m, HttpM' m, ServerM m, ServerAddressM m, PayloadM q (Sessions p) m) => p -> Integer -> m ()
- hGetSession :: (MonadIO m, HttpM' m, ServerM m, PayloadM q (Sessions p) m) => m (Session p)
- hPutSession :: (MonadIO m, HttpM' m, ServerM m, ServerAddressM m, PayloadM q (Sessions p) m) => Session p -> m ()
- hDelSession :: forall q p m. (PayloadM q (Sessions p) m, HttpM' m, MonadIO m) => p -> m ()
- hWithSession :: (PayloadM q (Sessions p) m, MonadIO m, HttpM Request m) => (Session p -> Session p) -> m ()
- hSessionInfo :: (SessionM p m, SendM m) => m ()
- existingSessionVarOrNew :: (Applicative m, MonadIO m, HttpM Request m, PayloadM q (Sessions p) m) => m (TVar (Session p))
- whenNotExpired :: MonadIO m => TVar (Session p) -> m (Maybe (TVar (Session p)))
- setCookieSession :: (MonadIO m, ServerM m, ServerAddressM m, HttpM Response m) => SessionID -> UTCTime -> m ()
- getCookieSessionID :: (MonadIO m, HttpM Request m) => m (Maybe SessionID)
- delCookieSession :: HttpM Response m => m ()
- newSessionVar :: (MonadIO m, PayloadM q (Sessions p) m) => m (TVar (Session p))
- newSessionID :: (MonadState (Sessions p) m, Functor m) => [SessionID] -> m SessionID
- willExpireAt :: Session p -> UTCTime
- lookupSessionVar :: (MonadIO m, PayloadM q (Sessions p) m) => SessionID -> m (Maybe (TVar (Session p)))
- newVar :: MonadIO m => a -> m (TVar a)
- getVar :: MonadIO m => TVar a -> m a
- putVar :: MonadIO m => TVar a -> a -> m ()
- modVar :: MonadIO m => (a -> a) -> TVar a -> m (TVar a)
Documentation
A session identifier. Should be unique for every session.
The session data type with polymorphic payload.
class (Applicative m, Monad m) => SessionM p m | m -> p whereSource
Session type classes that hides the inner workings from the outside world.
prolongSession :: Integer -> m ()Source
getSession :: m (Session p)Source
putSession :: Session p -> m ()Source
delSession :: m ()Source
withSession :: (Session p -> Session p) -> m ()Source
type SessionMap p = Map SessionID (TVar (Session p))Source
A mapping from unique session IDs to shared session variables.
Sessions | |
|
withSessions :: (SessionMap p -> SessionMap p) -> Sessions p -> Sessions pSource
Apply a function to the sessions in the Sessions
newtype.
mkSessions :: Sessions pSource
Create a new, empty, store of sessions.
hProlongSession :: forall m q p. (MonadIO m, HttpM' m, ServerM m, ServerAddressM m, PayloadM q (Sessions p) m) => p -> Integer -> m ()Source
todo doc:
The session handler. This handler will try to return an existing session from
the sessions map based on a session identifier found in the HTTP cookie
. When
such a session can be found the expiration date will be updated to a number of
seconds in the future. When no session can be found a new one will be created.
A cookie will be set that informs the client of the current session.
hPutSession :: (MonadIO m, HttpM' m, ServerM m, ServerAddressM m, PayloadM q (Sessions p) m) => Session p -> m ()Source
hWithSession :: (PayloadM q (Sessions p) m, MonadIO m, HttpM Request m) => (Session p -> Session p) -> m ()Source
hSessionInfo :: (SessionM p m, SendM m) => m ()Source
existingSessionVarOrNew :: (Applicative m, MonadIO m, HttpM Request m, PayloadM q (Sessions p) m) => m (TVar (Session p))Source
todo:
Given an existing session identifier lookup a session from the session map.
When no session is available, or the session is expired, create a new one using
the newSessionVar
function. Otherwise the expiration date of the existing
session is updated.
setCookieSession :: (MonadIO m, ServerM m, ServerAddressM m, HttpM Response m) => SessionID -> UTCTime -> m ()Source
This handler sets the HTTP cookie for the specified session. It will
use a default cookie with an additional sid
attribute with the
session identifier as value. The session expiration date will be used
as the cookie expire field. The session is valid for all subdomains.
getCookieSessionID :: (MonadIO m, HttpM Request m) => m (Maybe SessionID)Source
Given the (possibly wrong) request cookie, try to recover the existing session identifier.
delCookieSession :: HttpM Response m => m ()Source
newSessionVar :: (MonadIO m, PayloadM q (Sessions p) m) => m (TVar (Session p))Source
Create a new session with a specified expiration date. The session will be stored in the session map.
newSessionID :: (MonadState (Sessions p) m, Functor m) => [SessionID] -> m SessionIDSource
willExpireAt :: Session p -> UTCTimeSource