GHC 7
This commit is contained in:
parent
5894cc0fbd
commit
e6c3fdf15f
@ -3,6 +3,7 @@
|
|||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module Yesod.Helpers.Auth
|
module Yesod.Helpers.Auth
|
||||||
( -- * Subsite
|
( -- * Subsite
|
||||||
Auth
|
Auth
|
||||||
@ -73,11 +74,17 @@ class Yesod m => YesodAuth m where
|
|||||||
|
|
||||||
mkYesodSub "Auth"
|
mkYesodSub "Auth"
|
||||||
[ ClassP ''YesodAuth [VarT $ mkName "master"]
|
[ ClassP ''YesodAuth [VarT $ mkName "master"]
|
||||||
] [$parseRoutes|
|
]
|
||||||
|
#define STRINGS *Strings
|
||||||
|
#if GHC7
|
||||||
|
[parseRoutes|
|
||||||
|
#else
|
||||||
|
[$parseRoutes|
|
||||||
|
#endif
|
||||||
/check CheckR GET
|
/check CheckR GET
|
||||||
/login LoginR GET
|
/login LoginR GET
|
||||||
/logout LogoutR GET POST
|
/logout LogoutR GET POST
|
||||||
/page/#String/*Strings PluginR
|
/page/#String/STRINGS PluginR
|
||||||
|]
|
|]
|
||||||
|
|
||||||
credsKey :: String
|
credsKey :: String
|
||||||
@ -94,7 +101,13 @@ setCreds doRedirects creds = do
|
|||||||
then do
|
then do
|
||||||
case authRoute y of
|
case authRoute y of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
rh <- defaultLayout [$hamlet|%h1 Invalid login|]
|
rh <- defaultLayout
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
|
%h1 Invalid login|]
|
||||||
sendResponse rh
|
sendResponse rh
|
||||||
Just ar -> do
|
Just ar -> do
|
||||||
setMessage $ string "Invalid login"
|
setMessage $ string "Invalid login"
|
||||||
@ -115,7 +128,12 @@ getCheckR = do
|
|||||||
setTitle $ string "Authentication Status"
|
setTitle $ string "Authentication Status"
|
||||||
addHtml $ html creds) (json creds)
|
addHtml $ html creds) (json creds)
|
||||||
where
|
where
|
||||||
html creds = [$hamlet|
|
html creds =
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%h1 Authentication Status
|
%h1 Authentication Status
|
||||||
$maybe creds _
|
$maybe creds _
|
||||||
%p Logged in.
|
%p Logged in.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
-- | Provides a dummy authentication module that simply lets a user specify
|
-- | Provides a dummy authentication module that simply lets a user specify
|
||||||
-- his/her identifier. This is not intended for real world use, just for
|
-- his/her identifier. This is not intended for real world use, just for
|
||||||
-- testing.
|
-- testing.
|
||||||
@ -18,7 +19,12 @@ authDummy =
|
|||||||
setCreds True $ Creds "dummy" ident []
|
setCreds True $ Creds "dummy" ident []
|
||||||
dispatch _ _ = notFound
|
dispatch _ _ = notFound
|
||||||
url = PluginR "dummy" []
|
url = PluginR "dummy" []
|
||||||
login authToMaster = [$hamlet|
|
login authToMaster =
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%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
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE QuasiQuotes, TypeFamilies #-}
|
{-# LANGUAGE QuasiQuotes, TypeFamilies #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module Yesod.Helpers.Auth.Email
|
module Yesod.Helpers.Auth.Email
|
||||||
( authEmail
|
( authEmail
|
||||||
, YesodAuthEmail (..)
|
, YesodAuthEmail (..)
|
||||||
@ -62,22 +63,12 @@ class YesodAuth m => YesodAuthEmail m where
|
|||||||
|
|
||||||
authEmail :: YesodAuthEmail m => AuthPlugin m
|
authEmail :: YesodAuthEmail m => AuthPlugin m
|
||||||
authEmail =
|
authEmail =
|
||||||
AuthPlugin "email" dispatch login'
|
AuthPlugin "email" dispatch $ \tm ->
|
||||||
where
|
#if GHC7
|
||||||
go x = x >>= sendResponse
|
[hamlet|
|
||||||
dispatch "GET" ["register"] = go getRegisterR
|
#else
|
||||||
dispatch "POST" ["register"] = go postRegisterR
|
[$hamlet|
|
||||||
dispatch "GET" ["verify", eid, verkey] = do
|
#endif
|
||||||
y <- getYesod
|
|
||||||
case readAuthEmailId y eid of
|
|
||||||
Nothing -> notFound
|
|
||||||
Just eid' -> go $ getVerifyR eid' verkey
|
|
||||||
dispatch "POST" ["login"] = go postLoginR
|
|
||||||
dispatch "GET" ["set-password"] = go getPasswordR
|
|
||||||
dispatch "POST" ["set-password"] = go postPasswordR
|
|
||||||
dispatch _ _ = notFound
|
|
||||||
|
|
||||||
login' tm = [$hamlet|
|
|
||||||
%form!method=post!action=@tm.login@
|
%form!method=post!action=@tm.login@
|
||||||
%table
|
%table
|
||||||
%tr
|
%tr
|
||||||
@ -93,13 +84,30 @@ authEmail =
|
|||||||
%input!type=submit!value="Login via email"
|
%input!type=submit!value="Login via email"
|
||||||
%a!href=@tm.register@ I don't have an account
|
%a!href=@tm.register@ I don't have an account
|
||||||
|]
|
|]
|
||||||
|
where
|
||||||
|
dispatch "GET" ["register"] = getRegisterR >>= sendResponse
|
||||||
|
dispatch "POST" ["register"] = postRegisterR >>= sendResponse
|
||||||
|
dispatch "GET" ["verify", eid, verkey] = do
|
||||||
|
y <- getYesod
|
||||||
|
case readAuthEmailId y eid of
|
||||||
|
Nothing -> notFound
|
||||||
|
Just eid' -> getVerifyR eid' verkey >>= sendResponse
|
||||||
|
dispatch "POST" ["login"] = postLoginR >>= sendResponse
|
||||||
|
dispatch "GET" ["set-password"] = getPasswordR >>= sendResponse
|
||||||
|
dispatch "POST" ["set-password"] = postPasswordR >>= sendResponse
|
||||||
|
dispatch _ _ = notFound
|
||||||
|
|
||||||
getRegisterR :: YesodAuthEmail master => GHandler Auth master RepHtml
|
getRegisterR :: YesodAuthEmail master => GHandler Auth master RepHtml
|
||||||
getRegisterR = do
|
getRegisterR = do
|
||||||
toMaster <- getRouteToMaster
|
toMaster <- getRouteToMaster
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle $ string "Register a new account"
|
setTitle $ string "Register a new account"
|
||||||
addHamlet [$hamlet|
|
addHamlet
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%p Enter your e-mail address below, and a confirmation e-mail will be sent to you.
|
%p Enter your e-mail address below, and a confirmation e-mail will be sent to you.
|
||||||
%form!method=post!action=@toMaster.register@
|
%form!method=post!action=@toMaster.register@
|
||||||
%label!for=email E-mail
|
%label!for=email E-mail
|
||||||
@ -129,7 +137,12 @@ postRegisterR = do
|
|||||||
sendVerifyEmail email verKey verUrl
|
sendVerifyEmail email verKey verUrl
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle $ string "Confirmation e-mail sent"
|
setTitle $ string "Confirmation e-mail sent"
|
||||||
addWidget [$hamlet|
|
addWidget
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%p A confirmation e-mail has been sent to $email$.
|
%p A confirmation e-mail has been sent to $email$.
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -151,7 +164,12 @@ getVerifyR lid key = do
|
|||||||
_ -> return ()
|
_ -> return ()
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle $ string "Invalid verification key"
|
setTitle $ string "Invalid verification key"
|
||||||
addHtml [$hamlet|
|
addHtml
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%p I'm sorry, but that was an invalid verification key.
|
%p I'm sorry, but that was an invalid verification key.
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -191,7 +209,12 @@ getPasswordR = do
|
|||||||
redirect RedirectTemporary $ toMaster login
|
redirect RedirectTemporary $ toMaster login
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle $ string "Set password"
|
setTitle $ string "Set password"
|
||||||
addHamlet [$hamlet|
|
addHamlet
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%h3 Set a new password
|
%h3 Set a new password
|
||||||
%form!method=post!action=@toMaster.setpass@
|
%form!method=post!action=@toMaster.setpass@
|
||||||
%table
|
%table
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module Yesod.Helpers.Auth.Facebook
|
module Yesod.Helpers.Auth.Facebook
|
||||||
( authFacebook
|
( authFacebook
|
||||||
, facebookUrl
|
, facebookUrl
|
||||||
@ -53,7 +54,12 @@ authFacebook cid secret perms =
|
|||||||
render <- liftHandler getUrlRender
|
render <- liftHandler getUrlRender
|
||||||
let fb = Facebook.Facebook cid secret $ render $ tm url
|
let fb = Facebook.Facebook cid secret $ render $ tm url
|
||||||
let furl = Facebook.getForwardUrl fb $ perms
|
let furl = Facebook.getForwardUrl fb $ perms
|
||||||
addHtml [$hamlet|
|
addHtml
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%p
|
%p
|
||||||
%a!href=$furl$ Login with Facebook
|
%a!href=$furl$ Login with Facebook
|
||||||
|]
|
|]
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module Yesod.Helpers.Auth.OpenId
|
module Yesod.Helpers.Auth.OpenId
|
||||||
( authOpenId
|
( authOpenId
|
||||||
, forwardUrl
|
, forwardUrl
|
||||||
@ -20,12 +21,22 @@ authOpenId =
|
|||||||
name = "openid_identifier"
|
name = "openid_identifier"
|
||||||
login tm = do
|
login tm = do
|
||||||
ident <- newIdent
|
ident <- newIdent
|
||||||
addCassius [$cassius|
|
addCassius
|
||||||
#$ident$
|
#if GHC7
|
||||||
|
[cassius|
|
||||||
|
#else
|
||||||
|
[$cassius|
|
||||||
|
#endif
|
||||||
|
#$ident$
|
||||||
background: #fff url(http://www.myopenid.com/static/openid-icon-small.gif) no-repeat scroll 0pt 50%;
|
background: #fff url(http://www.myopenid.com/static/openid-icon-small.gif) no-repeat scroll 0pt 50%;
|
||||||
padding-left: 18px;
|
padding-left: 18px;
|
||||||
|]
|
|]
|
||||||
addHamlet [$hamlet|
|
addHamlet
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%form!method=get!action=@tm.forwardUrl@
|
%form!method=get!action=@tm.forwardUrl@
|
||||||
%label!for=openid OpenID: $
|
%label!for=openid OpenID: $
|
||||||
%input#$ident$!type=text!name=$name$!value="http://"
|
%input#$ident$!type=text!name=$name$!value="http://"
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module Yesod.Helpers.Auth.Rpxnow
|
module Yesod.Helpers.Auth.Rpxnow
|
||||||
( authRpxnow
|
( authRpxnow
|
||||||
) where
|
) where
|
||||||
@ -17,7 +18,12 @@ authRpxnow app apiKey =
|
|||||||
where
|
where
|
||||||
login tm = do
|
login tm = do
|
||||||
let url = {- FIXME urlEncode $ -} tm $ PluginR "rpxnow" []
|
let url = {- FIXME urlEncode $ -} tm $ PluginR "rpxnow" []
|
||||||
addHamlet [$hamlet|
|
addHamlet
|
||||||
|
#if GHC7
|
||||||
|
[hamlet|
|
||||||
|
#else
|
||||||
|
[$hamlet|
|
||||||
|
#endif
|
||||||
%iframe!src="http://$app$.rpxnow.com/openid/embed?token_url=@url@"!scrolling=no!frameBorder=no!allowtransparency=true!style="width:400px;height:240px"
|
%iframe!src="http://$app$.rpxnow.com/openid/embed?token_url=@url@"!scrolling=no!frameBorder=no!allowtransparency=true!style="width:400px;height:240px"
|
||||||
|]
|
|]
|
||||||
dispatch _ [] = do
|
dispatch _ [] = do
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-auth
|
name: yesod-auth
|
||||||
version: 0.2.0.1
|
version: 0.2.0.2
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
@ -11,9 +11,15 @@ cabal-version: >= 1.6
|
|||||||
build-type: Simple
|
build-type: Simple
|
||||||
homepage: http://docs.yesodweb.com/
|
homepage: http://docs.yesodweb.com/
|
||||||
|
|
||||||
|
flag ghc7
|
||||||
|
|
||||||
library
|
library
|
||||||
build-depends: base >= 4 && < 5
|
if flag(ghc7)
|
||||||
, authenticate >= 0.7 && < 0.8
|
build-depends: base >= 4.3 && < 5
|
||||||
|
cpp-options: -DGHC7
|
||||||
|
else
|
||||||
|
build-depends: base >= 4 && < 4.3
|
||||||
|
build-depends: authenticate >= 0.7 && < 0.8
|
||||||
, bytestring >= 0.9.1.4 && < 0.10
|
, bytestring >= 0.9.1.4 && < 0.10
|
||||||
, yesod >= 0.6 && < 0.7
|
, yesod >= 0.6 && < 0.7
|
||||||
, wai >= 0.2 && < 0.3
|
, wai >= 0.2 && < 0.3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user