hamlet 0.9

This commit is contained in:
Michael Snoyman 2011-07-19 09:39:05 +03:00
parent c566eafb34
commit 686950992d
6 changed files with 18 additions and 21 deletions

View File

@ -39,7 +39,7 @@ import qualified Data.Map as Map
import Language.Haskell.TH.Syntax hiding (lift) import Language.Haskell.TH.Syntax hiding (lift)
import qualified Network.Wai as W import qualified Network.Wai as W
import Text.Hamlet (hamlet) import Text.Hamlet (html)
import Yesod.Core import Yesod.Core
import Yesod.Persist import Yesod.Persist
@ -119,7 +119,7 @@ setCreds doRedirects creds = do
Nothing -> Nothing ->
when doRedirects $ do when doRedirects $ do
case authRoute y of case authRoute y of
Nothing -> do rh <- defaultLayout [QQ(hamlet)| <h1>Invalid login |] Nothing -> do rh <- defaultLayout $ addHtml [QQ(html)| <h1>Invalid login |]
sendResponse rh sendResponse rh
Just ar -> do setMessageI Msg.InvalidLogin Just ar -> do setMessageI Msg.InvalidLogin
redirect RedirectTemporary ar redirect RedirectTemporary ar
@ -134,10 +134,10 @@ getCheckR = do
creds <- maybeAuthId creds <- maybeAuthId
defaultLayoutJson (do defaultLayoutJson (do
setTitle "Authentication Status" setTitle "Authentication Status"
addHtml $ html creds) (json' creds) addHtml $ html' creds) (json' creds)
where where
html creds = html' creds =
[QQ(hamlet)| [QQ(html)|
<h1>Authentication Status <h1>Authentication Status
$maybe _ <- creds $maybe _ <- creds
<p>Logged in. <p>Logged in.

View File

@ -14,6 +14,7 @@ import Yesod.Auth
import Yesod.Form (runInputPost, textField, ireq) import Yesod.Form (runInputPost, textField, ireq)
import Yesod.Handler (notFound) import Yesod.Handler (notFound)
import Text.Hamlet (hamlet) import Text.Hamlet (hamlet)
import Yesod.Widget (addHamlet)
authDummy :: YesodAuth m => AuthPlugin m authDummy :: YesodAuth m => AuthPlugin m
authDummy = authDummy =
@ -25,7 +26,7 @@ authDummy =
dispatch _ _ = notFound dispatch _ _ = notFound
url = PluginR "dummy" [] url = PluginR "dummy" []
login authToMaster = login authToMaster =
[QQ(hamlet)| addHamlet [QQ(hamlet)|
<form method="post" action="@{authToMaster url}"> <form method="post" action="@{authToMaster url}">
\Your new identifier is: \Your new identifier is:
<input type="text" name="ident"> <input type="text" name="ident">

View File

@ -35,8 +35,6 @@ import Yesod.Content
import Yesod.Widget import Yesod.Widget
import Yesod.Core import Yesod.Core
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Class (lift)
import Web.Routes.Quasi (toSinglePiece, fromSinglePiece)
import qualified Yesod.Auth.Message as Msg import qualified Yesod.Auth.Message as Msg
loginR, registerR, setpassR :: AuthRoute loginR, registerR, setpassR :: AuthRoute
@ -82,9 +80,7 @@ class (YesodAuth m, SinglePiece (AuthEmailId m)) => YesodAuthEmail m where
authEmail :: YesodAuthEmail m => AuthPlugin m authEmail :: YesodAuthEmail m => AuthPlugin m
authEmail = authEmail =
AuthPlugin "email" dispatch $ \tm -> do AuthPlugin "email" dispatch $ \tm ->
y <- lift getYesod
l <- lift languages
[QQ(whamlet)| [QQ(whamlet)|
<form method="post" action="@{tm loginR}"> <form method="post" action="@{tm loginR}">
<table> <table>

View File

@ -76,7 +76,8 @@ import Yesod.Persist
import Yesod.Handler import Yesod.Handler
import Yesod.Form import Yesod.Form
import Yesod.Auth import Yesod.Auth
import Text.Hamlet (hamlet) import Yesod.Widget (addHamlet)
import Text.Hamlet (hamlet, html)
import Control.Applicative ((<$>), (<*>)) import Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM,liftM) import Control.Monad (replicateM,liftM)
@ -163,7 +164,7 @@ postLoginR uniq = do
(validateUser <$> (uniq =<< mu) <*> mp) (validateUser <$> (uniq =<< mu) <*> mp)
if isValid if isValid
then setCreds True $ Creds "hashdb" (fromMaybe "" mu) [] then setCreds True $ Creds "hashdb" (fromMaybe "" mu) []
else do setMessage [QQ(hamlet)| Invalid username/password |] else do setMessage [QQ(html)| Invalid username/password |]
toMaster <- getRouteToMaster toMaster <- getRouteToMaster
redirect RedirectTemporary $ toMaster LoginR redirect RedirectTemporary $ toMaster LoginR
@ -191,7 +192,7 @@ getAuthIdHashDB authR uniq creds = do
-- user exists -- user exists
Just (uid, _) -> return $ Just uid Just (uid, _) -> return $ Just uid
Nothing -> do Nothing -> do
setMessage [QQ(hamlet)| User not found |] setMessage [QQ(html)| User not found |]
redirect RedirectTemporary $ authR LoginR redirect RedirectTemporary $ authR LoginR
-- | Prompt for username and password, validate that against a database -- | Prompt for username and password, validate that against a database
@ -201,7 +202,7 @@ authHashDB :: ( YesodAuth m, YesodPersist m
, PersistEntity user , PersistEntity user
, PersistBackend (YesodDB m (GGHandler Auth m IO))) , PersistBackend (YesodDB m (GGHandler Auth m IO)))
=> (Text -> Maybe (Unique user)) -> AuthPlugin m => (Text -> Maybe (Unique user)) -> AuthPlugin m
authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> addHamlet
[QQ(hamlet)| [QQ(hamlet)|
<div id="header"> <div id="header">
<h1>Login <h1>Login

View File

@ -13,7 +13,7 @@ import Yesod.Auth
import Yesod.Form import Yesod.Form
import Yesod.Handler import Yesod.Handler
import Yesod.Widget import Yesod.Widget
import Text.Hamlet (hamlet) import Text.Hamlet (html)
import Web.Authenticate.OAuth import Web.Authenticate.OAuth
import Data.Maybe import Data.Maybe
import Data.String import Data.String
@ -69,7 +69,7 @@ authOAuth name ident reqUrl accUrl authUrl key sec = AuthPlugin name dispatch lo
render <- lift getUrlRender render <- lift getUrlRender
let oaUrl = render $ tm $ oauthUrl name let oaUrl = render $ tm $ oauthUrl name
addHtml addHtml
[QQ(hamlet)| <a href=#{oaUrl}>Login with #{name} |] [QQ(html)| <a href=#{oaUrl}>Login with #{name} |]
authTwitter :: YesodAuth m => authTwitter :: YesodAuth m =>
String -- ^ Consumer Key String -- ^ Consumer Key

View File

@ -22,7 +22,7 @@ library
build-depends: base >= 4 && < 4.3 build-depends: base >= 4 && < 4.3
build-depends: authenticate >= 0.9 && < 0.10 build-depends: authenticate >= 0.9 && < 0.10
, bytestring >= 0.9.1.4 && < 0.10 , bytestring >= 0.9.1.4 && < 0.10
, yesod-core >= 0.8.3 && < 0.9 , yesod-core >= 0.9 && < 0.10
, wai >= 0.4 && < 0.5 , wai >= 0.4 && < 0.5
, template-haskell , template-haskell
, pureMD5 >= 1.1 && < 2.2 , pureMD5 >= 1.1 && < 2.2
@ -32,8 +32,8 @@ library
, mime-mail >= 0.3 && < 0.4 , mime-mail >= 0.3 && < 0.4
, blaze-html >= 0.4 && < 0.5 , blaze-html >= 0.4 && < 0.5
, yesod-persistent >= 0.2 && < 0.3 , yesod-persistent >= 0.2 && < 0.3
, hamlet >= 0.8.1 && < 0.9 , hamlet >= 0.9 && < 0.10
, yesod-json >= 0.1 && < 0.2 , yesod-json >= 0.2 && < 0.3
, containers >= 0.2 && < 0.5 , containers >= 0.2 && < 0.5
, yesod-form >= 0.3 && < 0.4 , yesod-form >= 0.3 && < 0.4
, transformers >= 0.2 && < 0.3 , transformers >= 0.2 && < 0.3
@ -42,7 +42,6 @@ library
, SHA >= 1.4.1.3 && < 1.5 , SHA >= 1.4.1.3 && < 1.5
, http-enumerator >= 0.6 && < 0.7 , http-enumerator >= 0.6 && < 0.7
, aeson >= 0.3.2.2 && < 0.4 , aeson >= 0.3.2.2 && < 0.4
, web-routes-quasi >= 0.7 && < 0.8
, pwstore-fast >= 2.1 && < 2.2 , pwstore-fast >= 2.1 && < 2.2
exposed-modules: Yesod.Auth exposed-modules: Yesod.Auth