From f82d08b32aaf184e83c31029aceb185a1e1c10c9 Mon Sep 17 00:00:00 2001 From: Casey Allred Date: Thu, 7 Dec 2017 13:56:53 -0700 Subject: [PATCH 1/3] add a way to control redirection to current location when redirectLogin is called --- yesod-auth/ChangeLog.md | 4 ++++ yesod-auth/Yesod/Auth.hs | 16 +++++++++++----- yesod-auth/yesod-auth.cabal | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/yesod-auth/ChangeLog.md b/yesod-auth/ChangeLog.md index 22786b33..c9bab6dd 100644 --- a/yesod-auth/ChangeLog.md +++ b/yesod-auth/ChangeLog.md @@ -1,3 +1,7 @@ +## 1.4.18 + +* Add redirectToCurrent to Yesod.Auth module for controlling setUltDestCurrent in redirectLogin + ## 1.4.17 * Add Show instance for user credentials `Creds` diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index dda8182f..ce75d583 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -166,8 +166,8 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage -- > when (isJust ma) $ -- > lift $ redirect HomeR -- or any other Handler code you want -- > defaultLoginHandler - -- - loginHandler :: HandlerT Auth (HandlerT master IO) Html + -- + loginHandler :: AuthHandler master Html loginHandler = defaultLoginHandler -- | Used for i18n of messages provided by this package. @@ -182,6 +182,12 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage redirectToReferer :: master -> Bool redirectToReferer _ = False + -- | When being redirected to the login page should the current page + -- be set to redirect back to. Default is 'True'. + -- @since 1.4.18 + redirectToCurrent :: master -> Bool + redirectToCurrent _ = True + -- | Return an HTTP connection manager that is stored in the foundation -- type. This allows backends to reuse persistent connections. If none of -- the backends you're using use HTTP connections, you can safely return @@ -550,15 +556,15 @@ requireAuthPair :: (YesodAuthPersist master, Typeable (AuthEntity master)) => HandlerT master IO (AuthId master, AuthEntity master) requireAuthPair = maybeAuthPair >>= maybe handleAuthLack return -handleAuthLack :: Yesod master => HandlerT master IO a +handleAuthLack :: YesodAuth master => HandlerT master IO a handleAuthLack = do aj <- acceptsJson if aj then notAuthenticated else redirectLogin -redirectLogin :: Yesod master => HandlerT master IO a +redirectLogin :: YesodAuth master => HandlerT master IO a redirectLogin = do y <- getYesod - setUltDestCurrent + when (redirectToCurrent y) setUltDestCurrent case authRoute y of Just z -> redirect z Nothing -> permissionDenied "Please configure authRoute" diff --git a/yesod-auth/yesod-auth.cabal b/yesod-auth/yesod-auth.cabal index face7de3..63d58051 100644 --- a/yesod-auth/yesod-auth.cabal +++ b/yesod-auth/yesod-auth.cabal @@ -1,5 +1,5 @@ name: yesod-auth -version: 1.4.16 +version: 1.4.18 license: MIT license-file: LICENSE author: Michael Snoyman, Patrick Brisbin From 30ccfc8089fcbe0c9240bf1db7e27f85f1a0cb4b Mon Sep 17 00:00:00 2001 From: Casey Allred Date: Thu, 7 Dec 2017 14:01:36 -0700 Subject: [PATCH 2/3] didn't mean to change this signature --- yesod-auth/Yesod/Auth.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index ce75d583..40dfbd2f 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -167,7 +167,7 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage -- > lift $ redirect HomeR -- or any other Handler code you want -- > defaultLoginHandler -- - loginHandler :: AuthHandler master Html + loginHandler :: HandlerT Auth (HandlerT master IO) Html loginHandler = defaultLoginHandler -- | Used for i18n of messages provided by this package. From e40178a8542bc3f6237a20159d75496017ae1b66 Mon Sep 17 00:00:00 2001 From: Casey Allred Date: Thu, 7 Dec 2017 14:24:48 -0700 Subject: [PATCH 3/3] adding link to the PR in changelog.md --- yesod-auth/ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-auth/ChangeLog.md b/yesod-auth/ChangeLog.md index 2f1032eb..095ccbd6 100644 --- a/yesod-auth/ChangeLog.md +++ b/yesod-auth/ChangeLog.md @@ -1,6 +1,6 @@ ## 1.4.21 -* Add redirectToCurrent to Yesod.Auth module for controlling setUltDestCurrent in redirectLogin +* Add redirectToCurrent to Yesod.Auth module for controlling setUltDestCurrent in redirectLogin [#1461](https://github.com/yesodweb/yesod/pull/1461) ## 1.4.20