redirect and redirectString

This commit is contained in:
Michael Snoyman 2010-04-30 09:10:32 +03:00
parent 84abd28af9
commit 22ef236fef
2 changed files with 14 additions and 7 deletions

View File

@ -34,6 +34,7 @@ module Yesod.Handler
-- * Special responses
, RedirectType (..)
, redirect
, redirectString
, sendFile
, notFound
, badMethod
@ -212,9 +213,15 @@ safeEh er = YesodApp $ \_ _ _ -> do
liftIO $ hPutStrLn stderr $ "Error handler errored out: " ++ show er
return (W.Status500, [], TypePlain, cs "Internal Server Error")
-- | Redirect to the given route.
redirect :: RedirectType -> Routes master -> GHandler sub master a
redirect rt url = do
r <- getUrlRenderMaster
redirectString rt $ r url
-- | Redirect to the given URL.
redirect :: RedirectType -> String -> GHandler sub master a
redirect rt url = Handler $ \_ -> return ([], HCRedirect rt url)
redirectString :: RedirectType -> String -> GHandler sub master a
redirectString rt url = Handler $ \_ -> return ([], HCRedirect rt url)
-- | Bypass remaining handler code and output the given file.
--

View File

@ -99,9 +99,9 @@ getOpenIdForward = do
let complete = render OpenIdComplete
res <- runAttemptT $ OpenId.getForwardUrl oid complete
attempt
(\err -> redirect RedirectTemporary
(\err -> redirectString RedirectTemporary -- FIXME
$ "/auth/openid/?message=" ++ encodeUrl (show err))
(redirect RedirectTemporary)
(redirectString RedirectTemporary)
res
getOpenIdComplete :: GHandler Auth master ()
@ -109,7 +109,7 @@ getOpenIdComplete = do
rr <- getRequest
let gets' = reqGetParams rr
res <- runAttemptT $ OpenId.authenticate gets'
let onFailure err = redirect RedirectTemporary
let onFailure err = redirectString RedirectTemporary -- FIXME
$ "/auth/openid/?message="
++ encodeUrl (show err)
let onSuccess (OpenId.Identifier ident) = do
@ -236,7 +236,7 @@ redirectSetDest rt dest = do
Nothing -> "/" -- should never happen anyway
dest' = ur dest
addCookie destCookieTimeout destCookieName curr'
redirect rt dest'
redirectString rt dest' -- FIXME use redirect?
-- | Read the 'destCookieName' cookie and redirect to this destination. If the
-- cookie is missing, then use the default path provided.
@ -248,4 +248,4 @@ redirectToDest rt def = do
(x:_) -> do
deleteCookie destCookieName
return x
redirect rt dest
redirectString rt dest -- FIXME use redirect?