snap-1.1.0.0: Top-level package for the Snap Web Framework

Safe HaskellNone
LanguageHaskell98

Snap.Snaplet.Session

Contents

Synopsis

Documentation

data SessionManager #

Any Haskell record that is a member of the ISessionManager typeclass can be stuffed inside a SessionManager to enable all session-related functionality.

To use sessions in your application, just find a Backend that would produce one for you inside of your Initializer. See initCookieSessionManager in CookieSession for a built-in option that would get you started.

withSession :: SnapletLens b SessionManager -> Handler b v a -> Handler b v a #

Wrap around a handler, committing any changes in the session at the end

commitSession :: Handler b SessionManager () #

Commit changes to session within the current request cycle

setInSession :: Text -> Text -> Handler b SessionManager () #

Set a key-value pair in the current session

getFromSession :: Text -> Handler b SessionManager (Maybe Text) #

Get a key from the current session

deleteFromSession :: Text -> Handler b SessionManager () #

Remove a key from the current session

csrfToken :: Handler b SessionManager Text #

Returns a CSRF Token unique to the current session

sessionToList :: Handler b SessionManager [(Text, Text)] #

Return session contents as an association list

resetSession :: Handler b SessionManager () #

Deletes the session cookie, effectively resetting the session

touchSession :: Handler b SessionManager () #

Touch the session so the timeout gets refreshed

Utilities Exported For Convenience

type SecureCookie t = (UTCTime, t) #

Arbitrary payload with timestamp.

getSecureCookie #

Arguments

:: (MonadSnap m, Serialize t) 
=> ByteString

Cookie name

-> Key

Encryption key

-> Maybe Int

Timeout in seconds

-> m (Maybe t) 

Get the cookie payload.

setSecureCookie #

Arguments

:: (MonadSnap m, Serialize t) 
=> ByteString

Cookie name

-> Maybe ByteString

Cookie domain

-> Key

Encryption key

-> Maybe Int

Max age in seconds

-> t

Serializable payload

-> m () 

Inject the payload.

expireSecureCookie #

Arguments

:: MonadSnap m 
=> ByteString

Cookie name

-> Maybe ByteString

Cookie domain

-> m () 

Expire secure cookie

Helper functions

encodeSecureCookie #

Arguments

:: (MonadIO m, Serialize t) 
=> Key

Encryption key

-> SecureCookie t

Payload

-> m ByteString 

Encode SecureCookie with key into injectable payload

decodeSecureCookie #

Arguments

:: Serialize a 
=> Key

Encryption key

-> ByteString

Encrypted payload

-> Maybe (SecureCookie a) 

Decode secure cookie payload wih key.

checkTimeout :: MonadSnap m => Maybe Int -> UTCTime -> m Bool #

Validate session against timeout policy.

  • If timeout is set to Nothing, never trigger a time-out.
  • Otherwise, do a regular time-out check based on current time and given timestamp.