salvia-sessions-1.0.0: Session support for the Salvia webserver.




newtype SessionID Source

A session identifier. Should be unique for every session.




_sid :: Integer

data Session p Source

The session data type with polymorphic payload.




Show p => Show (Session p) 

sID :: Session p :-> SessionIDSource

A globally unique session identifier.

sStart :: Session p :-> UTCTimeSource

The time the session started.

sLast :: Session p :-> UTCTimeSource

Last time session was used.

sExpire :: Session p :-> IntegerSource

Expire after this amount of time when unused.

sPayload :: Session p :-> Maybe pSource

The information this session stores.

class (Applicative m, Monad m) => SessionM p m | m -> p whereSource

Session type classes that hides the inner workings from the outside world.


Contains q (TVar (Sessions p)) => SessionM p (Handler q)

Default instance for the Handler context.

type SessionMap p = Map SessionID (TVar (Session p))Source

A mapping from unique session IDs to shared session variables.

newtype Sessions p Source




unSessions :: SessionMap p

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.

hDelSession :: forall q p m. (PayloadM q (Sessions p) m, HttpM' m, MonadIO m) => p -> 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.

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.

newVar :: MonadIO m => a -> m (TVar a)Source

getVar :: MonadIO m => TVar a -> m aSource

putVar :: MonadIO m => TVar a -> a -> m ()Source

modVar :: MonadIO m => (a -> a) -> TVar a -> m (TVar a)Source