apiary-clientsession 0.7.0.0 → 0.8.0.0
raw patch · 2 files changed
+25/−30 lines, 2 filesdep +reflectiondep ~apiarydep ~apiary-cookiePVP ok
version bump matches the API change (PVP)
Dependencies added: reflection
Dependency ranges changed: apiary, apiary-cookie
API changes (from Hackage documentation)
- Web.Apiary.ClientSession: session :: (Strategy w, Query a, HasSession) => ByteString -> Proxy (w a) -> Apiary (SNext w as a) b -> Apiary as b
+ Web.Apiary.ClientSession: session :: (Strategy w, Query a, HasSession, Monad n, Functor n) => ByteString -> Proxy (w a) -> ApiaryT (SNext w as a) n m b -> ApiaryT as n m b
- Web.Apiary.ClientSession: setRawSession :: HasSession => Maybe DiffTime -> SetCookie -> Action ()
+ Web.Apiary.ClientSession: setRawSession :: (MonadIO m, HasSession) => Maybe DiffTime -> SetCookie -> ActionT m ()
- Web.Apiary.ClientSession: setSession :: HasSession => ByteString -> ByteString -> Action ()
+ Web.Apiary.ClientSession: setSession :: (MonadIO m, HasSession) => ByteString -> ByteString -> ActionT m ()
- Web.Apiary.ClientSession: setSessionWith :: HasSession => (SetCookie -> SetCookie) -> ByteString -> ByteString -> Action ()
+ Web.Apiary.ClientSession: setSessionWith :: (MonadIO m, HasSession) => (SetCookie -> SetCookie) -> ByteString -> ByteString -> ActionT m ()
- Web.Apiary.ClientSession: type HasSession = ?webApiaryClientSessionSession :: Session
+ Web.Apiary.ClientSession: type HasSession = Given Session
Files
apiary-clientsession.cabal view
@@ -1,5 +1,5 @@ name: apiary-clientsession-version: 0.7.0.0+version: 0.8.0.0 synopsis: clientsession support for apiary web framework. description: example: <https://github.com/philopon/apiary/blob/master/examples/auth.hs>@@ -23,12 +23,13 @@ build-depends: base >=4.6 && <4.8 , mtl >=2.1 && <2.3 , bytestring >=0.10 && <0.11- , apiary >=0.7 && <0.8- , apiary-cookie >=0.7 && <0.8+ , apiary >=0.8 && <0.9+ , apiary-cookie >=0.8 && <0.9 , clientsession >=0.9 && <0.10 , tagged >=0.7 && <0.8 , time >=1.4 && <1.5 , data-default-class >=0.0 && <0.1+ , reflection >=1.4 && <1.5 hs-source-dirs: src ghc-options: -O2 -Wall
src/Web/Apiary/ClientSession/Internal.hs view
@@ -1,10 +1,8 @@ {-# LANGUAGE Rank2Types #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE LambdaCase #-}-{-# LANGUAGE ImplicitParams #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE RecordWildCards #-} @@ -19,6 +17,7 @@ import Data.Proxy import Data.Time import Data.Default.Class+import Data.Reflection import Control.Monad.Apiary.Filter.Internal import Control.Monad.Apiary.Filter.Internal.Strategy@@ -27,11 +26,7 @@ data Session = Session { key :: Key- , maxAge' :: Maybe DiffTime- , path' :: Maybe S.ByteString- , domain' :: Maybe S.ByteString- , httpOnly' :: Bool- , secure' :: Bool+ , config :: SessionConfig } data SessionConfig = SessionConfig@@ -47,17 +42,16 @@ def = SessionConfig defaultKeyFile (Just (24 * 60 * 60)) Nothing Nothing True True -type HasSession = ?webApiaryClientSessionSession :: Session+type HasSession = Given Session cond :: (a -> Bool) -> (a -> b) -> (a -> b) -> a -> b cond p t f a = if p a then t a else f a withSession :: MonadIO m => SessionConfig -> (HasSession => m b) -> m b-withSession SessionConfig{..} m = do+withSession cfg@SessionConfig{..} m = do k <- liftIO $ getKey keyFile- let ?webApiaryClientSessionSession = Session- k maxAge path domain httpOnly secure- m+ let sess = Session k cfg+ give sess m setMaxAge :: SetCookie -> Maybe DiffTime -> IO SetCookie setMaxAge s (Just a) = do@@ -69,37 +63,37 @@ encryptValue :: HasSession => SetCookie -> IO SetCookie encryptValue s = do- v' <- encryptIO (key ?webApiaryClientSessionSession) (setCookieValue s)+ v' <- encryptIO (key given) (setCookieValue s) return $ s { setCookieValue = v' } -setRawSession :: HasSession => Maybe DiffTime -> SetCookie -> Action ()+setRawSession :: (MonadIO m, HasSession) => Maybe DiffTime -> SetCookie -> ActionT m () setRawSession age s = do s' <- liftIO $ encryptValue =<< setMaxAge s age setCookie s' -setSessionWith :: HasSession+setSessionWith :: (MonadIO m, HasSession) => (SetCookie -> SetCookie) -- ^ postprocess -> S.ByteString -- ^ key -> S.ByteString -- ^ value- -> Action ()+ -> ActionT m () setSessionWith f k v = do- let Session{..} = ?webApiaryClientSessionSession- setRawSession maxAge' $ f def+ let Session{..} = given+ setRawSession (maxAge config) $ f def { setCookieName = k , setCookieValue = v- , setCookiePath = path'- , setCookieDomain = domain'- , setCookieHttpOnly = httpOnly'- , setCookieSecure = secure'+ , setCookiePath = path config+ , setCookieDomain = domain config+ , setCookieHttpOnly = httpOnly config+ , setCookieSecure = secure config } -setSession :: HasSession+setSession :: (MonadIO m, HasSession) => S.ByteString -- ^ key -> S.ByteString -- ^ value- -> Action ()+ -> ActionT m () setSession = setSessionWith id -session :: (Strategy w, Query a, HasSession)- => S.ByteString -> Proxy (w a) -> Apiary (SNext w as a) b -> Apiary as b+session :: (Strategy w, Query a, HasSession, Monad n, Functor n)+ => S.ByteString -> Proxy (w a) -> ApiaryT (SNext w as a) n m b -> ApiaryT as n m b session ky p = function $ \l r -> readStrategy readQuery ((ky ==) . fst) p- (map (\(k,b) -> (k, decrypt (key ?webApiaryClientSessionSession) b)) $ cookie' r) l+ (map (\(k,b) -> (k, decrypt (key given) b)) $ cookie' r) l