From 66ee5f4c96212d68f6f1d69b7e45f23bebd77fcc Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 20 Jan 2011 00:01:43 +0200 Subject: [PATCH] Fix HashDB; hamlet6to7; GGHandler IO --- Yesod/Helpers/Auth.hs | 15 +++---- Yesod/Helpers/Auth/Dummy.hs | 8 ++-- Yesod/Helpers/Auth/Email.hs | 70 ++++++++++++++++----------------- Yesod/Helpers/Auth/Facebook.hs | 4 +- Yesod/Helpers/Auth/HashDB.hs | 72 ++++++++++++++++++---------------- Yesod/Helpers/Auth/OpenId.hs | 13 +++--- Yesod/Helpers/Auth/Rpxnow.hs | 2 +- yesod-auth.cabal | 4 +- 8 files changed, 98 insertions(+), 90 deletions(-) diff --git a/Yesod/Helpers/Auth.hs b/Yesod/Helpers/Auth.hs index e7939043..ef978c29 100644 --- a/Yesod/Helpers/Auth.hs +++ b/Yesod/Helpers/Auth.hs @@ -166,7 +166,8 @@ setCreds doRedirects creds = do #else [$hamlet| #endif - %h1 Invalid login|] +

Invalid login +|] sendResponse rh Just ar -> do setMessage $ string "Invalid login" @@ -193,11 +194,11 @@ getCheckR = do #else [$hamlet| #endif -%h1 Authentication Status -$maybe creds _ - %p Logged in. +

Authentication Status +$maybe _ <- creds +

Logged in. $nothing - %p Not logged in. +

Not logged in. |] json creds = ValueObject $ Map.fromList @@ -237,7 +238,7 @@ maybeAuthId = do maybeAuth :: ( YesodAuth m , Key val ~ AuthId m - , PersistBackend (YesodDB m (GHandler s m)) + , PersistBackend (YesodDB m (GGHandler s m IO)) , PersistEntity val , YesodPersist m ) => GHandler s m (Maybe (Key val, val)) @@ -256,7 +257,7 @@ requireAuthId = maybeAuthId >>= maybe redirectLogin return requireAuth :: ( YesodAuth m , Key val ~ AuthId m - , PersistBackend (YesodDB m (GHandler s m)) + , PersistBackend (YesodDB m (GGHandler s m IO)) , PersistEntity val , YesodPersist m ) => GHandler s m (Key val, val) diff --git a/Yesod/Helpers/Auth/Dummy.hs b/Yesod/Helpers/Auth/Dummy.hs index 63cc92de..62694026 100644 --- a/Yesod/Helpers/Auth/Dummy.hs +++ b/Yesod/Helpers/Auth/Dummy.hs @@ -27,8 +27,8 @@ authDummy = #else [$hamlet| #endif -%form!method=post!action=@authToMaster.url@ - Your new identifier is: $ - %input!type=text!name=ident - %input!type=submit!value="Dummy Login" +

+ \Your new identifier is: + + |] diff --git a/Yesod/Helpers/Auth/Email.hs b/Yesod/Helpers/Auth/Email.hs index 7bb31ab8..08a16774 100644 --- a/Yesod/Helpers/Auth/Email.hs +++ b/Yesod/Helpers/Auth/Email.hs @@ -77,20 +77,20 @@ authEmail = #else [$hamlet| #endif -%form!method=post!action=@tm.login@ - %table - %tr - %th $messageEmail.y$ - %td - %input!type=email!name=email - %tr - %th $messagePassword.y$ - %td - %input!type=password!name=password - %tr - %td!colspan=2 - %input!type=submit!value="Login via email" - %a!href=@tm.register@ I don't have an account + + + + + +
#{messageEmail y} + + +
#{messagePassword y} + + +
+ + I don't have an account |] where dispatch "GET" ["register"] = getRegisterR >>= sendResponse @@ -117,11 +117,11 @@ getRegisterR = do #else [$hamlet| #endif -%p $messageEnterEmail.y$ -%form!method=post!action=@toMaster.register@ - %label!for=email $messageEmail y$ - %input!type=email!name=email!width=150 - %input!type=submit!value=$messageRegister y$ +

#{messageEnterEmail y} + +

#{messageConfirmationEmailSent y email} |] getVerifyR :: YesodAuthEmail m @@ -180,7 +180,7 @@ getVerifyR lid key = do #else [$hamlet| #endif -%p $messageInvalidKey y$ +

#{messageInvalidKey y} |] postLoginR :: YesodAuthEmail master => GHandler Auth master () @@ -227,20 +227,20 @@ getPasswordR = do #else [$hamlet| #endif -%h3 $messageSetPass y$ -%form!method=post!action=@toMaster.setpass@ - %table - %tr - %th $messageNewPass y$ - %td - %input!type=password!name=new - %tr - %th $messageConfirmPass y$ - %td - %input!type=password!name=confirm - %tr - %td!colspan=2 - %input!type=submit!value=$messageSetPassTitle y$ +

#{messageSetPass y} + + + + + +
#{messageNewPass y} + + +
#{messageConfirmPass y} + + +
+ |] postPasswordR :: YesodAuthEmail master => GHandler Auth master () diff --git a/Yesod/Helpers/Auth/Facebook.hs b/Yesod/Helpers/Auth/Facebook.hs index 4cfe7869..3ddeb76f 100644 --- a/Yesod/Helpers/Auth/Facebook.hs +++ b/Yesod/Helpers/Auth/Facebook.hs @@ -66,6 +66,6 @@ authFacebook cid secret perms = #else [$hamlet| #endif -%p - %a!href=$furl$ $messageFacebook y$ +

+ #{messageFacebook y} |] diff --git a/Yesod/Helpers/Auth/HashDB.hs b/Yesod/Helpers/Auth/HashDB.hs index 86673107..3020c08a 100644 --- a/Yesod/Helpers/Auth/HashDB.hs +++ b/Yesod/Helpers/Auth/HashDB.hs @@ -54,15 +54,18 @@ -- can be used to get the hash from the commandline. -- ------------------------------------------------------------------------------- -module Helpers.Auth.HashDB +module Yesod.Helpers.Auth.HashDB ( authHashDB , getAuthIdHashDB , UserId , migrateUsers ) where -import Yesod +import Yesod.Persist +import Yesod.Handler +import Yesod.Form import Yesod.Helpers.Auth +import Text.Hamlet (hamlet) import Control.Applicative ((<$>), (<*>)) import Data.ByteString.Lazy.Char8 (pack) @@ -85,7 +88,7 @@ User -- | Given a (user,password) in plaintext, validate them against the -- database values validateUser :: (YesodPersist y, - PersistBackend (YesodDB y (GHandler sub y))) + PersistBackend (YesodDB y (GGHandler sub y IO))) => (String, String) -> GHandler sub y Bool validateUser (user,password) = runDB (getBy $ UniqueUser user) >>= \dbUser -> @@ -101,7 +104,7 @@ login = PluginR "hashdb" ["login"] -- | Handle the login form postLoginR :: (YesodAuth y, YesodPersist y, - PersistBackend (YesodDB y (GHandler Auth y))) + PersistBackend (YesodDB y (GGHandler Auth y IO))) => GHandler Auth y () postLoginR = do (user, password) <- runFormPost' $ (,) @@ -113,14 +116,15 @@ postLoginR = do if isValid then setCreds True $ Creds "hashdb" user [] else do - setMessage $ [$hamlet| %em invalid username/password |] + setMessage $ [$hamlet| invalid username/password +|] toMaster <- getRouteToMaster redirect RedirectTemporary $ toMaster LoginR -- | A drop in for the getAuthId method of your YesodAuth instance which -- can be used if authHashDB is the only plugin in use. getAuthIdHashDB :: (Key User ~ AuthId master, - PersistBackend (YesodDB master (GHandler sub master)), + PersistBackend (YesodDB master (GGHandler sub master IO)), YesodPersist master, YesodAuth master) => (AuthRoute -> Route master) -- ^ your site's Auth Route @@ -137,41 +141,43 @@ getAuthIdHashDB authR creds = do -- user exists Just (uid, _) -> return $ Just uid Nothing -> do - setMessage $ [$hamlet| %em user not found |] + setMessage $ [$hamlet| user not found +|] redirect RedirectTemporary $ authR LoginR -- | Prompt for username and password, validate that against a database -- which holds the username and a hash of the password authHashDB :: (YesodAuth y, YesodPersist y, - PersistBackend (YesodDB y (GHandler Auth y))) + PersistBackend (YesodDB y (GGHandler Auth y IO))) => AuthPlugin y authHashDB = AuthPlugin "hashdb" dispatch $ \tm -> - [$hamlet| - #header - %h1 Login - - #login - %form!method=post!action=@tm.login@ - %table - %tr - %th Username: - %td - %input#x!name=username!autofocus - %tr - %th Password: - %td - %input!type=password!name=password - %tr - %td   - %td - %input!type=submit!value="Login" - - %script - if (!("autofocus" in document.createElement("input"))) { - document.getElementById("x").focus(); - } - |] + [$hamlet|\ +