happstack-clientsession-7.0.0: client-side session data

Safe HaskellNone

Happstack.Server.ClientSession

Synopsis

Documentation

class SafeCopy st => ClientSession st whereSource

Your session type must have an instance for this class.

Methods

empty :: stSource

An empty session, i.e. what you get when there is no existing session stored.

data SessionConf Source

Configuration for the session cookie for passing to runClientSessionT.

Constructors

SessionConf 

Fields

sessionCookieName :: String

Name of the cookie to hold your session data.

sessionCookieLife :: CookieLife

Lifetime of that cookie.

sessionKey :: Key

Encryption key, usually from getKey or getDefaultKey.

sessionSecure :: Bool

Only use a session over secure transports.

mkSessionConf :: Key -> SessionConfSource

Create a SessionConf using defaults for everything except sessionKey. You can use record update syntax to override individual fields.

 main = do key <- getDefaultKey
           let sessConf = (mkSessionConf key) { sessionCookieLife = oneWeek }
           simpleHTTP nullConf $ runClientSessionT handlers sessConf
   where
     oneWeek  = MaxAge $ 60 * 60 * 24 * 7
     handlers = sessionPart $ msum [...]

data ClientSessionT st m a Source

Transformer for monads capable of using a session.

runClientSessionT :: Monad m => ClientSessionT st m a -> SessionConf -> m aSource

Get the inner monad of a ClientSessionT.

getSession :: (Functor m, MonadPlus m, HasRqData m, ClientSession st) => ClientSessionT st m stSource

Get the session value. If the cookie has not been decoded yet, it will be decoded. If no session data is stored or the session has been expired, empty is returned.

putSession :: (Monad m, ClientSession st) => st -> ClientSessionT st m ()Source

Put a new value in the session.

expireSession :: Monad m => ClientSessionT st m ()Source

Expire the session, i.e. the cookie holding it.

withSession :: (Functor m, MonadPlus m, HasRqData m, ClientSession st, Eq st) => State st a -> ClientSessionT st m aSource

Run a State monad with the session.

sessionPart :: (Functor m, Monad m, MonadIO m, FilterMonad Response m, ClientSession st) => ClientSessionT st m a -> ClientSessionT st m aSource

Wrapper around your handlers that use the session. Takes care of expiring the cookie of an expired session, or encrypting a modified session into the cookie.