Skip to content
Permalink
Browse files

copy / paste yesod dummy auth

  • Loading branch information...
3v0k4 committed Aug 17, 2019
1 parent 70e7148 commit 78e13f807f5674aa0a84e2633d7967fa02b755cf
Showing with 23 additions and 3 deletions.
  1. +23 −3 src/Foundation.hs
@@ -7,6 +7,8 @@
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE FlexibleContexts #-}

module Foundation where

@@ -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)
@@ -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

0 comments on commit 78e13f8

Please sign in to comment.
You can’t perform that action at this time.