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

View File

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