我想在未登录时将用户重定向到“登录”页面时显示一条消息。
资源授权:
isAuthorized AdminR _ = isAdmin
isAuthorized _ _ = return Authorized
和
isAdmin = do
mu <- maybeAuthId
return $ case mu of
Just "Foo" -> Authorized
Just _ -> Unauthorized "You are NOT a Admin !"
Nothing -> do
setMessage "You have to Login "
return AuthenticationRequired
错误:
Couldn't match type `m0 AuthResult' with `AuthResult'
Expected type: m0 () -> m0 AuthResult -> AuthResult
Actual type: m0 () -> m0 AuthResult -> m0 AuthResult
In a stmt of a 'do' block: setMessage "You have to Login "
In the expression:
do { setMessage "You have to Login ";
return AuthenticationRequired }
In a case alternative:
Nothing
-> do { setMessage "You have to Login ";
return AuthenticationRequired }
那么,如何从那个Monad中解除AuthResult?
答案 0 :(得分:0)
由于您在案件结束时正在执行monad操作,因此您无需退回案例。
isAdmin = do
mu <- maybeAuthId
case mu of
Just "Foo" -> Authorized
Just _ -> Unauthorized "You are NOT a Admin !"
Nothing -> do
setMessage "You have to Login "
return AuthenticationRequired