Skip to content

Commit

Permalink
copy / paste yesod dummy auth
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed Aug 17, 2019
1 parent 70e7148 commit 78e13f8
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE FlexibleContexts #-}

module Foundation where

Expand All @@ -16,9 +18,6 @@ import Text.Hamlet (hamletFile)
import Text.Jasmine (minifym)
import Control.Monad.Logger (LogSource)

-- Used only when in "auth-dummy-login" setting is enabled.
import Yesod.Auth.Dummy

import Yesod.Auth.OpenId (authOpenId, IdentifierType (Claimed))
import Yesod.Default.Util (addStaticContentExternal)
import Yesod.Core.Types (Logger)
Expand Down Expand Up @@ -270,6 +269,27 @@ instance YesodAuth App where
authPlugins :: App -> [AuthPlugin App]
authPlugins _app = [authDummy]

authDummy :: YesodAuth m => AuthPlugin m
authDummy =
AuthPlugin "dummy" dispatch login
where
dispatch "POST" [] = do
ident <- runInputPost $ ireq textField "ident"
setCredsRedirect $ Creds "dummy" ident []
dispatch _ _ = notFound
url = PluginR "dummy" []
login authToMaster = do
request <- getRequest
toWidget [hamlet|
$newline never
<form method="post" action="@{authToMaster url}">
$maybe t <- reqToken request
<input type=hidden name=#{defaultCsrfParamName} value=#{t}>
Your new identifier is: #
<input type="text" name="ident">
<input type="submit" value="Dummy Login">
|]

-- | Access function to determine if a user is logged in.
isAuthenticated :: Handler AuthResult
isAuthenticated = do
Expand Down

0 comments on commit 78e13f8

Please sign in to comment.