From c44ee5509ee03a5ff90980b6d840805852a0117a Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Fri, 13 May 2011 09:01:48 +0300 Subject: [PATCH] yesod-form 0.2 --- Yesod/Auth/Dummy.hs | 4 ++-- Yesod/Auth/Email.hs | 15 +++++++-------- Yesod/Auth/Facebook.hs | 2 +- Yesod/Auth/HashDB.hs | 6 +++--- Yesod/Auth/OAuth.hs | 6 ++++-- Yesod/Auth/OpenId.hs | 7 +++---- yesod-auth.cabal | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Yesod/Auth/Dummy.hs b/Yesod/Auth/Dummy.hs index 405a7ea5..d210f0d4 100644 --- a/Yesod/Auth/Dummy.hs +++ b/Yesod/Auth/Dummy.hs @@ -9,7 +9,7 @@ module Yesod.Auth.Dummy ) where import Yesod.Auth -import Yesod.Form (runFormPost', stringInput) +import Yesod.Form (runInputPost, textField, ireq) import Yesod.Handler (notFound) import Text.Hamlet (hamlet) @@ -18,7 +18,7 @@ authDummy = AuthPlugin "dummy" dispatch login where dispatch "POST" [] = do - ident <- runFormPost' $ stringInput "ident" + ident <- runInputPost $ ireq textField "ident" setCreds True $ Creds "dummy" ident [] dispatch _ _ = notFound url = PluginR "dummy" [] diff --git a/Yesod/Auth/Email.hs b/Yesod/Auth/Email.hs index 8ca0a996..8c76173d 100644 --- a/Yesod/Auth/Email.hs +++ b/Yesod/Auth/Email.hs @@ -136,7 +136,7 @@ getRegisterR = do postRegisterR :: YesodAuthEmail master => GHandler Auth master RepHtml postRegisterR = do y <- getYesod - email <- runFormPost' $ emailInput "email" + email <- runInputPost $ ireq emailField "email" mecreds <- getEmailCreds email (lid, verKey) <- case mecreds of @@ -196,9 +196,9 @@ getVerifyR lid key = do postLoginR :: YesodAuthEmail master => GHandler Auth master () postLoginR = do - (email, pass) <- runFormPost' $ (,) - <$> emailInput "email" - <*> stringInput "password" + (email, pass) <- runInputPost $ (,) + <$> ireq emailField "email" + <*> ireq textField "password" mecreds <- getEmailCreds email maid <- case (mecreds >>= emailCredsAuthId, fmap emailCredsStatus mecreds) of @@ -215,7 +215,6 @@ postLoginR = do Just _aid -> setCreds True $ Creds "email" email [("verifiedEmail", email)] -- FIXME aid? Nothing -> do - y <- getYesod mr <- getMessageRender setMessage $ mr Msg.InvalidEmailPass toMaster <- getRouteToMaster @@ -257,9 +256,9 @@ getPasswordR = do postPasswordR :: YesodAuthEmail master => GHandler Auth master () postPasswordR = do - (new, confirm) <- runFormPost' $ (,) - <$> stringInput "new" - <*> stringInput "confirm" + (new, confirm) <- runInputPost $ (,) + <$> ireq textField "new" + <*> ireq textField "confirm" toMaster <- getRouteToMaster y <- getYesod when (new /= confirm) $ do diff --git a/Yesod/Auth/Facebook.hs b/Yesod/Auth/Facebook.hs index b10713a1..b3c84a95 100644 --- a/Yesod/Auth/Facebook.hs +++ b/Yesod/Auth/Facebook.hs @@ -46,7 +46,7 @@ authFacebook cid secret perms = render <- getUrlRender tm <- getRouteToMaster let fb = Facebook.Facebook cid secret $ render $ tm url - code <- runFormGet' $ stringInput "code" + code <- runInputGet $ ireq textField "code" at <- liftIO $ Facebook.getAccessToken fb code let Facebook.AccessToken at' = at so <- liftIO $ Facebook.getGraphData at "me" diff --git a/Yesod/Auth/HashDB.hs b/Yesod/Auth/HashDB.hs index 14e346e8..96cd1459 100644 --- a/Yesod/Auth/HashDB.hs +++ b/Yesod/Auth/HashDB.hs @@ -115,9 +115,9 @@ postLoginR :: (YesodAuth y, PersistBackend (YesodDB y (GGHandler Auth y IO))) => GHandler Auth y () postLoginR = do - (mu,mp) <- runFormPost' $ (,) - <$> maybeStringInput "username" - <*> maybeStringInput "password" + (mu,mp) <- runInputPost $ (,) + <$> iopt textField "username" + <*> iopt textField "password" isValid <- case (mu,mp) of (Nothing, _ ) -> return False diff --git a/Yesod/Auth/OAuth.hs b/Yesod/Auth/OAuth.hs index 347425d5..5fa3712d 100644 --- a/Yesod/Auth/OAuth.hs +++ b/Yesod/Auth/OAuth.hs @@ -22,6 +22,7 @@ import Data.Text (Text, unpack) import Data.Text.Encoding (encodeUtf8, decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import Data.ByteString (ByteString) +import Control.Applicative ((<$>), (<*>)) oauthUrl :: Text -> AuthRoute oauthUrl name = PluginR name ["forward"] @@ -51,8 +52,9 @@ authOAuth name ident reqUrl accUrl authUrl key sec = AuthPlugin name dispatch lo tok <- liftIO $ getTemporaryCredential oauth' redirectText RedirectTemporary (fromString $ authorizeUrl oauth' tok) dispatch "GET" [] = do - verifier <- runFormGet' $ stringInput "oauth_verifier" - oaTok <- runFormGet' $ stringInput "oauth_token" + (verifier, oaTok) <- runInputGet $ (,) + <$> ireq textField "oauth_verifier" + <*> ireq textField "oauth_token" let reqTok = Credential [ ("oauth_verifier", encodeUtf8 verifier), ("oauth_token", encodeUtf8 oaTok) ] accTok <- liftIO $ getAccessToken oauth reqTok diff --git a/Yesod/Auth/OpenId.hs b/Yesod/Auth/OpenId.hs index 8df638c6..68255862 100644 --- a/Yesod/Auth/OpenId.hs +++ b/Yesod/Auth/OpenId.hs @@ -56,10 +56,9 @@ authOpenId = |] dispatch "GET" ["forward"] = do - (roid, _, _) <- runFormGet $ stringInput name - y <- getYesod + roid <- runInputGet $ iopt textField name case roid of - FormSuccess oid -> do + Just oid -> do render <- getUrlRender toMaster <- getRouteToMaster let complete' = render $ toMaster complete @@ -71,7 +70,7 @@ authOpenId = ) (redirectText RedirectTemporary) res - _ -> do + Nothing -> do toMaster <- getRouteToMaster mr <- getMessageRender setMessage $ mr Msg.NoOpenID diff --git a/yesod-auth.cabal b/yesod-auth.cabal index b7155af4..f43b4cc4 100644 --- a/yesod-auth.cabal +++ b/yesod-auth.cabal @@ -1,5 +1,5 @@ name: yesod-auth -version: 0.5.0 +version: 0.6.0 license: BSD3 license-file: LICENSE author: Michael Snoyman, Patrick Brisbin @@ -34,7 +34,7 @@ library , hamlet >= 0.8.1 && < 0.9 , yesod-json >= 0.1 && < 0.2 , containers >= 0.2 && < 0.5 - , yesod-form >= 0.1 && < 0.2 + , yesod-form >= 0.2 && < 0.3 , transformers >= 0.2 && < 0.3 , persistent >= 0.5 && < 0.6 , persistent-template >= 0.5 && < 0.6