{-#LANGUAGE NoImplicitPrelude #-}
{-#LANGUAGE OverloadedStrings #-}
{-#LANGUAGE OverloadedLists #-}
{-#LANGUAGE LambdaCase #-}
{-#LANGUAGE TupleSections #-}
module Web.Sprinkles.SessionStore
where
import Web.Sprinkles.Prelude
import Data.Time.Clock.POSIX
type SessionID = ByteString
data SessionExpiry = NeverExpires | Expires POSIXTime
deriving (Show, Eq)
data SessionNotFoundException = SessionNotFoundException
deriving (Show)
instance Exception SessionNotFoundException where
data SessionSupportDisabled = SessionSupportDisabled
deriving (Show)
instance Exception SessionSupportDisabled where
data SessionStore =
SessionStore
{ ssGet :: SessionID -> Text -> IO (Maybe Text)
, ssList :: SessionID -> IO [Text]
, ssGetAll :: SessionID -> IO [(Text,Text)]
, ssPut :: SessionID -> Text -> Text -> IO ()
, ssCreateSession :: SessionID -> SessionExpiry -> IO ()
, ssDropSession :: SessionID -> IO ()
, ssDoesSessionExist :: SessionID -> IO Bool
}
nullSessionStore =
SessionStore
{ ssGet = const . const $ return Nothing
, ssList = const $ return []
, ssGetAll = const $ return []
, ssPut = const . const . const $ return ()
, ssCreateSession = const . const $ throwM SessionSupportDisabled
, ssDropSession = const $ return ()
, ssDoesSessionExist = const $ return False
}