{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Web.Spock.SessionActions
( SessionId
, sessionRegenerateId, getSessionId, readSession, writeSession
, modifySession, modifySession', modifyReadSession, mapAllSessions, clearAllSessions
)
where
import Web.Spock.Action
import Web.Spock.Internal.Monad ()
import Web.Spock.Internal.SessionManager
import Web.Spock.Internal.Types
sessionRegenerateId :: SpockActionCtx ctx conn sess st ()
sessionRegenerateId =
runInContext () $
getSessMgr >>= sm_regenerateSessionId
getSessionId :: SpockActionCtx ctx conn sess st SessionId
getSessionId =
runInContext () $
getSessMgr >>= sm_getSessionId
writeSession :: forall sess ctx conn st. sess -> SpockActionCtx ctx conn sess st ()
writeSession d =
do mgr <- getSessMgr
runInContext () $ sm_writeSession mgr d
modifySession :: (sess -> sess) -> SpockActionCtx ctx conn sess st ()
modifySession f =
modifySession' $ \sess -> (f sess, ())
modifySession' :: (sess -> (sess, a)) -> SpockActionCtx ctx conn sess st a
modifySession' f =
do mgr <- getSessMgr
runInContext () $ sm_modifySession mgr f
modifyReadSession :: (sess -> sess) -> SpockActionCtx ctx conn sess st sess
modifyReadSession f =
modifySession' $ \sess ->
let x = f sess
in (x, x)
readSession :: SpockActionCtx ctx conn sess st sess
readSession =
runInContext () $
do mgr <- getSessMgr
sm_readSession mgr
clearAllSessions :: SpockActionCtx ctx conn sess st ()
clearAllSessions =
do mgr <- getSessMgr
runInContext () $ sm_clearAllSessions mgr
mapAllSessions :: (forall m. Monad m => sess -> m sess) -> SpockActionCtx ctx conn sess st ()
mapAllSessions f =
do mgr <- getSessMgr
runInContext () $ sm_mapSessions mgr f