我正在尝试设置硬编码身份验证以依赖在中指定的登录信息
config/settings.yml
从Yesod脚手架上。我写了以下代码:
instance YesodAuthHardcoded App where
validatePassword u = do
app <- getYesod
let user = appUser $ appSettings app
return . validPassword user u . fromString . unpack
doesUserNameExist = do
app <- getYesod
return . isJust . lookupUser app
我收到以下错误消息
validatePassord
相当于
doesUserNameExist
:
⢠Couldn't match type âHandlerSite ((->) Text)â with âAppâ
Expected type: Text -> App
Actual type: Text -> HandlerSite ((->) Text)
⢠In a stmt of a 'do' block: app <- getYesod
In the expression:
do { app <- getYesod;
let user = appUser $ appSettings app;
return . validPassword user u . fromString . unpack }
In an equation for âvalidatePasswordâ:
validatePassword u
= do { app <- getYesod;
let user = ...;
return . validPassword user u . fromString . unpack }
原型
validatePassword
is defined in
Yesod.Auth.Hardcoded
:
validatePassword :: Text -> Text -> AuthHandler site Bool
和
AuthHandler
is defined in
Yesod.Auth
:
type MonadAuthHandler master m = (MonadHandler m, YesodAuth master, master ~ HandlerSite m, Auth ~ SubHandlerSite m, MonadUnliftIO m)
type AuthHandler master a = forall m. MonadAuthHandler master m => m a
终于
getYesod
is defined as follow in
Yesod.Core.Handler
:
getYesod :: MonadHandler m => m (HandlerSite m)
从这些定义看来,我应该有办法
盖耶索德
从
自动处理程序
但我不知道怎么做。
编辑:
我已经更新了
yesod
以及最新版本的脚手架。我也修改了
验证密码
如下:
validatePassword u = do
app <- liftHandler . getYesod
let user = appUser $ appSettings app
return . validPassword user u . fromString . unpack
我得到以下错误消息:
⢠Couldn't match type âm1 a1â with âAppâ
Expected type: HandlerFor (HandlerSite m1) a1 -> App
Actual type: HandlerFor (HandlerSite m1) a1 -> m1 a1
⢠In the first argument of â(.)â, namely âliftHandlerâ
In a stmt of a 'do' block: app <- liftHandler . getYesod
In the expression:
do app <- liftHandler . getYesod
let user = appUser $ appSettings app
return . validPassword user u . fromString . unpack
|
259 | app <- liftHandler . getYesod
|