Merge branch 'patch-2' of https://github.com/cblp/yesod into yesod-1.4

This commit is contained in:
Michael Snoyman 2014-07-26 21:20:49 +03:00
commit 575e222605

View File

@ -479,18 +479,23 @@ type YesodAuthPersist master =
type AuthEntity master = KeyEntity (AuthId master) type AuthEntity master = KeyEntity (AuthId master)
-- | Similar to 'maybeAuthId', but redirects to a login page if user is not -- | Similar to 'maybeAuthId', but redirects to a login page if user is not
-- authenticated. -- authenticated or responds with error 401 if this is an API client (expecting JSON).
-- --
-- Since 1.1.0 -- Since 1.1.0
requireAuthId :: YesodAuth master => HandlerT master IO (AuthId master) requireAuthId :: YesodAuth master => HandlerT master IO (AuthId master)
requireAuthId = maybeAuthId >>= maybe redirectLogin return requireAuthId = maybeAuthId >>= maybe handleAuthLack return
-- | Similar to 'maybeAuth', but redirects to a login page if user is not -- | Similar to 'maybeAuth', but redirects to a login page if user is not
-- authenticated. -- authenticated or responds with error 401 if this is an API client (expecting JSON).
-- --
-- Since 1.1.0 -- Since 1.1.0
requireAuth :: YesodAuthPersist master => HandlerT master IO (Entity (AuthEntity master)) requireAuth :: YesodAuthPersist master => HandlerT master IO (Entity (AuthEntity master))
requireAuth = maybeAuth >>= maybe redirectLogin return requireAuth = maybeAuth >>= maybe handleAuthLack return
handleAuthLack :: Yesod master => HandlerT master IO a
handleAuthLack = do
aj <- acceptsJson
if aj then notAuthenticated else redirectLogin
redirectLogin :: Yesod master => HandlerT master IO a redirectLogin :: Yesod master => HandlerT master IO a
redirectLogin = do redirectLogin = do