Add encryptKey and clientSessionDuration for 0.10 compatibility

This commit is contained in:
Luite Stegeman 2012-02-11 20:33:26 +01:00
parent b5b27f2b15
commit a37beb3447

View File

@ -160,6 +160,18 @@ class RenderRoute a => Yesod a where
approot :: Approot a
approot = ApprootRelative
-- | The encryption key to be used for encrypting client sessions.
-- Returning 'Nothing' disables sessions.
-- this method will be removed in Yesod 1.0, use makeSessionBackend instead
encryptKey :: a -> IO (Maybe CS.Key)
encryptKey _ = fmap Just $ CS.getKey CS.defaultKeyFile
-- | Number of minutes before a client session times out. Defaults to
-- 120 (2 hours).
-- this method will be removed in Yesod 1.0, use makeSessionBackend instead
clientSessionDuration :: a -> Int
clientSessionDuration = const 120
-- | Output error response pages.
errorHandler :: ErrorResponse -> GHandler sub a ChooseRep
errorHandler = defaultErrorHandler
@ -316,7 +328,10 @@ class RenderRoute a => Yesod a where
-- | Create a session backend
makeSessionBackend :: a -> IO (Maybe (SessionBackend a))
makeSessionBackend _ = Just <$> defaultClientSessionBackend
makeSessionBackend a = do
key <- encryptKey a
return $
(\k -> clientSessionBackend k (clientSessionDuration a)) <$> key
type Session = [(Text, S8.ByteString)]