From fb02d71d73294a998e413d9b91fde566caf7de39 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 27 Nov 2012 16:57:46 +0200 Subject: [PATCH 1/5] Persistent 1.1 --- yesod-auth/Yesod/Auth.hs | 13 +++++++ yesod-auth/Yesod/Auth/HashDB.hs | 49 +++++++++++++++++++++++-- yesod-auth/yesod-auth.cabal | 4 +- yesod-form/Yesod/Form/Fields.hs | 11 +++++- yesod-form/yesod-form.cabal | 2 +- yesod-persistent/Yesod/Persist.hs | 23 ++++++++++++ yesod-persistent/yesod-persistent.cabal | 4 +- yesod-test/yesod-test.cabal | 4 +- 8 files changed, 98 insertions(+), 12 deletions(-) diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index 62e06d61..944c8dc8 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -233,10 +233,17 @@ handlePluginR plugin pieces = do ap:_ -> apDispatch ap method pieces maybeAuth :: ( YesodAuth m +#if MIN_VERSION_persistent(1, 1, 0) + , PersistMonadBackend (b (GHandler s m)) ~ PersistEntityBackend val + , b ~ YesodPersistBackend m + , Key val ~ AuthId m + , PersistStore (b (GHandler s m)) +#else , b ~ YesodPersistBackend m , b ~ PersistEntityBackend val , Key b val ~ AuthId m , PersistStore b (GHandler s m) +#endif , PersistEntity val , YesodPersist m ) => GHandler s m (Maybe (Entity val)) @@ -250,9 +257,15 @@ requireAuthId = maybeAuthId >>= maybe redirectLogin return requireAuth :: ( YesodAuth m , b ~ YesodPersistBackend m +#if MIN_VERSION_persistent(1, 1, 0) + , PersistMonadBackend (b (GHandler s m)) ~ PersistEntityBackend val + , Key val ~ AuthId m + , PersistStore (b (GHandler s m)) +#else , b ~ PersistEntityBackend val , Key b val ~ AuthId m , PersistStore b (GHandler s m) +#endif , PersistEntity val , YesodPersist m ) => GHandler s m (Entity val) diff --git a/yesod-auth/Yesod/Auth/HashDB.hs b/yesod-auth/Yesod/Auth/HashDB.hs index 1e400aeb..3e7f7feb 100644 --- a/yesod-auth/Yesod/Auth/HashDB.hs +++ b/yesod-auth/Yesod/Auth/HashDB.hs @@ -5,6 +5,7 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE CPP #-} ------------------------------------------------------------------------------- -- | -- Module : Yesod.Auth.HashDB @@ -133,14 +134,24 @@ setPassword pwd u = do salt <- randomSalt -- | Given a user ID and password in plaintext, validate them against -- the database values. validateUser :: ( YesodPersist yesod +#if MIN_VERSION_persistent(1, 1, 0) + , b ~ YesodPersistBackend yesod + , PersistMonadBackend (b (GHandler sub yesod)) ~ PersistEntityBackend user + , PersistUnique (b (GHandler sub yesod)) +#else , b ~ YesodPersistBackend yesod , b ~ PersistEntityBackend user , PersistStore b (GHandler sub yesod) , PersistUnique b (GHandler sub yesod) +#endif , PersistEntity user , HashDBUser user ) => +#if MIN_VERSION_persistent(1, 1, 0) + Unique user -- ^ User unique identifier +#else Unique user b -- ^ User unique identifier +#endif -> Text -- ^ Password in plaint-text -> GHandler sub yesod Bool validateUser userID passwd = do @@ -160,12 +171,23 @@ login = PluginR "hashdb" ["login"] -- | Handle the login form. First parameter is function which maps -- username (whatever it might be) to unique user ID. postLoginR :: ( YesodAuth y, YesodPersist y + , HashDBUser user, PersistEntity user +#if MIN_VERSION_persistent(1, 1, 0) + , b ~ YesodPersistBackend y + , PersistMonadBackend (b (GHandler Auth y)) ~ PersistEntityBackend user + , PersistUnique (b (GHandler Auth y)) +#else , b ~ YesodPersistBackend y , b ~ PersistEntityBackend user - , HashDBUser user, PersistEntity user , PersistStore b (GHandler Auth y) - , PersistUnique b (GHandler Auth y)) - => (Text -> Maybe (Unique user b)) + , PersistUnique b (GHandler Auth y) +#endif + ) +#if MIN_VERSION_persistent(1, 1, 0) + => (Text -> Maybe (Unique user)) +#else + => (Text -> Maybe (Unique user b)) +#endif -> GHandler Auth y () postLoginR uniq = do (mu,mp) <- runInputPost $ (,) @@ -185,13 +207,25 @@ postLoginR uniq = do -- can be used if authHashDB is the only plugin in use. getAuthIdHashDB :: ( YesodAuth master, YesodPersist master , HashDBUser user, PersistEntity user +#if MIN_VERSION_persistent(1, 1, 0) + , Key user ~ AuthId master + , b ~ YesodPersistBackend master + , PersistMonadBackend (b (GHandler sub master)) ~ PersistEntityBackend user + , PersistUnique (b (GHandler sub master)) +#else , Key b user ~ AuthId master , b ~ YesodPersistBackend master , b ~ PersistEntityBackend user , PersistUnique b (GHandler sub master) - , PersistStore b (GHandler sub master)) + , PersistStore b (GHandler sub master) +#endif + ) => (AuthRoute -> Route master) -- ^ your site's Auth Route +#if MIN_VERSION_persistent(1, 1, 0) + -> (Text -> Maybe (Unique user)) -- ^ gets user ID +#else -> (Text -> Maybe (Unique user b)) -- ^ gets user ID +#endif -> Creds master -- ^ the creds argument -> GHandler sub master (Maybe (AuthId master)) getAuthIdHashDB authR uniq creds = do @@ -215,11 +249,18 @@ getAuthIdHashDB authR uniq creds = do authHashDB :: ( YesodAuth m, YesodPersist m , HashDBUser user , PersistEntity user +#if MIN_VERSION_persistent(1, 1, 0) + , b ~ YesodPersistBackend m + , PersistMonadBackend (b (GHandler Auth m)) ~ PersistEntityBackend user + , PersistUnique (b (GHandler Auth m))) + => (Text -> Maybe (Unique user)) -> AuthPlugin m +#else , b ~ YesodPersistBackend m , b ~ PersistEntityBackend user , PersistStore b (GHandler Auth m) , PersistUnique b (GHandler Auth m)) => (Text -> Maybe (Unique user b)) -> AuthPlugin m +#endif authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> toWidget [hamlet| $newline never