removed QQ hacks from yesod-auth

This commit is contained in:
Pascal Wittmann 2012-03-15 22:08:19 +01:00
parent ba1e083edc
commit f4e743e50d
9 changed files with 18 additions and 49 deletions

View File

@ -1,9 +1,9 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE QuasiQuotes, TypeFamilies, TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
@ -27,8 +27,6 @@ module Yesod.Auth
, AuthException (..)
) where
#include "qq.h"
import Control.Monad (when)
import Control.Monad.Trans.Maybe
@ -132,7 +130,7 @@ mkYesodSub "Auth"
[ ClassP ''YesodAuth [VarT $ mkName "master"]
]
#define STRINGS *Texts
[QQ(parseRoutes)|
[parseRoutes|
/check CheckR GET
/login LoginR GET
/logout LogoutR GET POST
@ -151,7 +149,7 @@ setCreds doRedirects creds = do
Nothing ->
when doRedirects $ do
case authRoute y of
Nothing -> do rh <- defaultLayout $ addHtml [QQ(shamlet)| <h1>Invalid login |]
Nothing -> do rh <- defaultLayout $ addHtml [shamlet| <h1>Invalid login |]
sendResponse rh
Just ar -> do setMessageI Msg.InvalidLogin
redirect ar
@ -169,7 +167,7 @@ getCheckR = do
addHtml $ html' creds) (jsonCreds creds)
where
html' creds =
[QQ(shamlet)|
[shamlet|
<h1>Authentication Status
$maybe _ <- creds
<p>Logged in.

View File

@ -1,5 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Yesod.Auth.BrowserId
( authBrowserId
@ -16,8 +15,6 @@ import Data.Maybe (fromMaybe)
import Control.Monad.IO.Class (liftIO)
import Control.Exception (throwIO)
#include "qq.h"
pid :: Text
pid = "browserid"
@ -64,7 +61,7 @@ helper maudience = AuthPlugin
_ -> notFound
, apLogin = \toMaster -> do
addScriptRemote browserIdJs
addHamlet [QQ(hamlet)|
addHamlet [hamlet|
<p>
<a href="javascript:navigator.id.getVerifiedEmail(function(a){if(a)document.location='@{toMaster complete}/'+a});">
<img src="https://browserid.org/i/sign_in_green.png">

View File

@ -1,5 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Provides a dummy authentication module that simply lets a user specify
-- his/her identifier. This is not intended for real world use, just for
@ -8,8 +7,6 @@ module Yesod.Auth.Dummy
( authDummy
) where
#include "qq.h"
import Yesod.Auth
import Yesod.Form (runInputPost, textField, ireq)
import Yesod.Handler (notFound)
@ -26,7 +23,7 @@ authDummy =
dispatch _ _ = notFound
url = PluginR "dummy" []
login authToMaster =
addHamlet [QQ(hamlet)|
addHamlet [hamlet|
<form method="post" action="@{authToMaster url}">
\Your new identifier is:
<input type="text" name="ident">

View File

@ -1,5 +1,4 @@
{-# LANGUAGE QuasiQuotes, TypeFamilies #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
module Yesod.Auth.Email
@ -15,8 +14,6 @@ module Yesod.Auth.Email
, isValidPass
) where
#include "qq.h"
import Network.Mail.Mime (randomString)
import Yesod.Auth
import System.Random
@ -82,7 +79,7 @@ class (YesodAuth m, PathPiece (AuthEmailId m)) => YesodAuthEmail m where
authEmail :: YesodAuthEmail m => AuthPlugin m
authEmail =
AuthPlugin "email" dispatch $ \tm ->
[QQ(whamlet)|
[whamlet|
<form method="post" action="@{tm loginR}">
<table>
<tr>
@ -116,7 +113,7 @@ getRegisterR = do
defaultLayout $ do
setTitleI Msg.RegisterLong
addWidget
[QQ(whamlet)|
[whamlet|
<p>_{Msg.EnterEmail}
<form method="post" action="@{toMaster registerR}">
<label for="email">_{Msg.Email}
@ -147,7 +144,7 @@ postRegisterR = do
defaultLayout $ do
setTitleI Msg.ConfirmationEmailSentTitle
addWidget
[QQ(whamlet)| <p>_{Msg.ConfirmationEmailSent email} |]
[whamlet| <p>_{Msg.ConfirmationEmailSent email} |]
getVerifyR :: YesodAuthEmail m
=> AuthEmailId m -> Text -> GHandler Auth m RepHtml
@ -168,7 +165,7 @@ getVerifyR lid key = do
defaultLayout $ do
setTitleI Msg.InvalidKey
addWidget
[QQ(whamlet)| <p>_{Msg.InvalidKey} |]
[whamlet| <p>_{Msg.InvalidKey} |]
postLoginR :: YesodAuthEmail master => GHandler Auth master ()
postLoginR = do
@ -207,7 +204,7 @@ getPasswordR = do
defaultLayout $ do
setTitleI Msg.SetPassTitle
addWidget
[QQ(whamlet)|
[whamlet|
<h3>_{Msg.SetPass}
<form method="post" action="@{toMaster setpassR}">
<table>

View File

@ -1,5 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Use an email address as an identifier via Google's OpenID login system.
--

View File

@ -2,7 +2,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GADTs #-}
@ -72,8 +71,6 @@ module Yesod.Auth.HashDB
, migrateUsers
) where
#include "qq.h"
import Yesod.Persist
import Yesod.Handler
import Yesod.Form
@ -179,7 +176,7 @@ postLoginR uniq = do
(validateUser <$> (uniq =<< mu) <*> mp)
if isValid
then setCreds True $ Creds "hashdb" (fromMaybe "" mu) []
else do setMessage [QQ(shamlet)| Invalid username/password |]
else do setMessage [shamlet| Invalid username/password |]
toMaster <- getRouteToMaster
redirect $ toMaster LoginR
@ -210,7 +207,7 @@ getAuthIdHashDB authR uniq creds = do
-- user exists
Just (Entity uid _) -> return $ Just uid
Nothing -> do
setMessage [QQ(shamlet)| User not found |]
setMessage [shamlet| User not found |]
redirect $ authR LoginR
-- | Prompt for username and password, validate that against a database
@ -224,7 +221,7 @@ authHashDB :: ( YesodAuth m, YesodPersist m
, PersistUnique b (GHandler Auth m))
=> (Text -> Maybe (Unique user b)) -> AuthPlugin m
authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> addHamlet
[QQ(hamlet)|
[hamlet|
<div id="header">
<h1>Login
@ -261,7 +258,7 @@ authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> addHamlet
-- | Generate data base instances for a valid user
share [mkPersist sqlSettings, mkMigrate "migrateUsers"]
[QQ(persistUpperCase)|
[persistUpperCase|
User
username Text Eq
password Text

View File

@ -1,5 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Yesod.Auth.OpenId
( authOpenId
@ -7,8 +6,6 @@ module Yesod.Auth.OpenId
, forwardUrl
) where
#include "qq.h"
import Yesod.Auth
import qualified Web.Authenticate.OpenId as OpenId
@ -37,11 +34,11 @@ authOpenIdExtended extensionFields =
login tm = do
ident <- lift newIdent
addCassius
[QQ(cassius)|##{ident}
[cassius|##{ident}
background: #fff url(http://www.myopenid.com/static/openid-icon-small.gif) no-repeat scroll 0pt 50%;
padding-left: 18px;
|]
[QQ(whamlet)|
[whamlet|
<form method="get" action="@{tm forwardUrl}">
<input type="hidden" name="openid_identifier" value="https://www.google.com/accounts/o8/id">
<button .openid-google>_{Msg.LoginGoogle}

View File

@ -1,12 +1,9 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Yesod.Auth.Rpxnow
( authRpxnow
) where
#include "qq.h"
import Yesod.Auth
import qualified Web.Authenticate.Rpxnow as Rpxnow
import Control.Monad (mplus)
@ -28,7 +25,7 @@ authRpxnow app apiKey =
login tm = do
let url = {- FIXME urlEncode $ -} tm $ PluginR "rpxnow" []
addHamlet
[QQ(hamlet)|
[hamlet|
<iframe src="http://#{app}.rpxnow.com/openid/embed?token_url=@{url}" scrolling="no" frameBorder="no" allowtransparency="true" style="width:400px;height:240px">
|]
dispatch _ [] = do

View File

@ -1,10 +0,0 @@
-- CPP macro which choses which quasyquotes syntax to use depending
-- on GHC version.
--
-- QQ stands for quasyquote.
#if GHC7
# define QQ(x) x
#else
# define QQ(x) $x
#endif