From a37beb3447a737a52acb4ebaf7d485542a834d33 Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Sat, 11 Feb 2012 20:33:26 +0100 Subject: [PATCH] Add encryptKey and clientSessionDuration for 0.10 compatibility --- yesod-core/Yesod/Internal/Core.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/yesod-core/Yesod/Internal/Core.hs b/yesod-core/Yesod/Internal/Core.hs index 338045e8..13691993 100644 --- a/yesod-core/Yesod/Internal/Core.hs +++ b/yesod-core/Yesod/Internal/Core.hs @@ -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)]