isAuthorized
This commit is contained in:
parent
3ba6be616f
commit
56ac260207
@ -176,14 +176,18 @@ toWaiApp' y segments env = do
|
|||||||
(urlRenderOverride y u)
|
(urlRenderOverride y u)
|
||||||
rr <- parseWaiRequest env session'
|
rr <- parseWaiRequest env session'
|
||||||
onRequest y rr
|
onRequest y rr
|
||||||
let ya = case eurl of
|
ya <-
|
||||||
Left _ -> runHandler (errorHandler y NotFound)
|
case eurl of
|
||||||
render
|
Left _ -> return $ runHandler (errorHandler y NotFound)
|
||||||
Nothing
|
render
|
||||||
id
|
Nothing
|
||||||
y
|
id
|
||||||
id
|
y
|
||||||
Right url -> quasiDispatch site
|
id
|
||||||
|
Right url -> do
|
||||||
|
auth <- isAuthorized y url
|
||||||
|
case auth of
|
||||||
|
Nothing -> return $ quasiDispatch site
|
||||||
render
|
render
|
||||||
url
|
url
|
||||||
id
|
id
|
||||||
@ -191,6 +195,14 @@ toWaiApp' y segments env = do
|
|||||||
id
|
id
|
||||||
(badMethodApp method)
|
(badMethodApp method)
|
||||||
method
|
method
|
||||||
|
Just msg ->
|
||||||
|
return $ runHandler
|
||||||
|
(errorHandler y $ PermissionDenied msg)
|
||||||
|
render
|
||||||
|
(Just url)
|
||||||
|
id
|
||||||
|
y
|
||||||
|
id
|
||||||
let eurl' = either (const Nothing) Just eurl
|
let eurl' = either (const Nothing) Just eurl
|
||||||
let eh er = runHandler (errorHandler y er) render eurl' id y id
|
let eh er = runHandler (errorHandler y er) render eurl' id y id
|
||||||
(s, hs, ct, c, sessionFinal) <- unYesodApp ya eh rr types
|
(s, hs, ct, c, sessionFinal) <- unYesodApp ya eh rr types
|
||||||
|
|||||||
@ -361,7 +361,7 @@ badMethod = do
|
|||||||
|
|
||||||
-- | Return a 403 permission denied page.
|
-- | Return a 403 permission denied page.
|
||||||
permissionDenied :: Failure ErrorResponse m => m a
|
permissionDenied :: Failure ErrorResponse m => m a
|
||||||
permissionDenied = failure PermissionDenied
|
permissionDenied = failure $ PermissionDenied "Permission denied"
|
||||||
|
|
||||||
-- | Return a 400 invalid arguments page.
|
-- | Return a 400 invalid arguments page.
|
||||||
invalidArgs :: Failure ErrorResponse m => [(ParamName, String)] -> m a
|
invalidArgs :: Failure ErrorResponse m => [(ParamName, String)] -> m a
|
||||||
@ -408,7 +408,7 @@ getStatus :: ErrorResponse -> W.Status
|
|||||||
getStatus NotFound = W.Status404
|
getStatus NotFound = W.Status404
|
||||||
getStatus (InternalError _) = W.Status500
|
getStatus (InternalError _) = W.Status500
|
||||||
getStatus (InvalidArgs _) = W.Status400
|
getStatus (InvalidArgs _) = W.Status400
|
||||||
getStatus PermissionDenied = W.Status403
|
getStatus (PermissionDenied _) = W.Status403
|
||||||
getStatus (BadMethod _) = W.Status405
|
getStatus (BadMethod _) = W.Status405
|
||||||
|
|
||||||
getRedirectStatus :: RedirectType -> W.Status
|
getRedirectStatus :: RedirectType -> W.Status
|
||||||
|
|||||||
@ -14,7 +14,7 @@ data ErrorResponse =
|
|||||||
NotFound
|
NotFound
|
||||||
| InternalError String
|
| InternalError String
|
||||||
| InvalidArgs [(String, String)]
|
| InvalidArgs [(String, String)]
|
||||||
| PermissionDenied
|
| PermissionDenied String
|
||||||
| BadMethod String
|
| BadMethod String
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
|||||||
@ -82,6 +82,14 @@ class Yesod a where
|
|||||||
urlRenderOverride :: a -> Routes a -> Maybe String
|
urlRenderOverride :: a -> Routes a -> Maybe String
|
||||||
urlRenderOverride _ _ = Nothing
|
urlRenderOverride _ _ = Nothing
|
||||||
|
|
||||||
|
-- | Determine is a request is authorized or not.
|
||||||
|
--
|
||||||
|
-- Return 'Nothing' is the request is authorized, 'Just' a message if
|
||||||
|
-- unauthorized. If authentication is required, you should use a redirect;
|
||||||
|
-- the Auth helper provides this functionality automatically.
|
||||||
|
isAuthorized :: a -> Routes a -> IO (Maybe String)
|
||||||
|
isAuthorized _ _ = return Nothing
|
||||||
|
|
||||||
-- | Apply the default layout ('defaultLayout') to the given title and body.
|
-- | Apply the default layout ('defaultLayout') to the given title and body.
|
||||||
applyLayout :: Yesod master
|
applyLayout :: Yesod master
|
||||||
=> String -- ^ title
|
=> String -- ^ title
|
||||||
@ -130,9 +138,11 @@ defaultErrorHandler NotFound = do
|
|||||||
|]
|
|]
|
||||||
where
|
where
|
||||||
pathInfo = W.pathInfo
|
pathInfo = W.pathInfo
|
||||||
defaultErrorHandler PermissionDenied =
|
defaultErrorHandler (PermissionDenied msg) =
|
||||||
applyLayout' "Permission Denied" $ [$hamlet|
|
applyLayout' "Permission Denied" $ [$hamlet|
|
||||||
%h1 Permission denied|]
|
%h1 Permission denied
|
||||||
|
%p $cs.msg$
|
||||||
|
|]
|
||||||
defaultErrorHandler (InvalidArgs ia) =
|
defaultErrorHandler (InvalidArgs ia) =
|
||||||
applyLayout' "Invalid Arguments" $ [$hamlet|
|
applyLayout' "Invalid Arguments" $ [$hamlet|
|
||||||
%h1 Invalid Arguments
|
%h1 Invalid Arguments
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod
|
name: yesod
|
||||||
version: 0.2.0
|
version: 0.2.1
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user