From f5f84e830da299486d8a74941b3f32c191b4bf52 Mon Sep 17 00:00:00 2001 From: Kirilll Zaborsky Date: Tue, 9 Apr 2013 09:25:30 +0400 Subject: [PATCH 1/2] Added clearCreds symmetric to setCreds function --- yesod-auth/Yesod/Auth.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index 415e478a..83ec6492 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -18,6 +18,7 @@ module Yesod.Auth -- * Plugin interface , Creds (..) , setCreds + , clearCreds -- * User functions , defaultMaybeAuthId , maybeAuth @@ -184,6 +185,14 @@ $newline never onLogin redirectUltDest $ loginDest y +clearCreds :: YesodAuth master => Bool -> GHandler sub master () +clearCreds doRedirects = do + y <- getYesod + deleteSession credsKey + when doRedirects $ do + onLogout + redirectUltDest $ logoutDest y + getCheckR :: YesodAuth master => GHandler Auth master RepHtmlJson getCheckR = do creds <- maybeAuthId @@ -219,11 +228,7 @@ getLogoutR = do setUltDestReferer' >> redirectToPost (tm LogoutR) postLogoutR :: YesodAuth master => GHandler Auth master () -postLogoutR = do - y <- getYesod - deleteSession credsKey - onLogout - redirectUltDest $ logoutDest y +postLogoutR = clearCreds True handlePluginR :: YesodAuth master => Text -> [Text] -> GHandler Auth master () handlePluginR plugin pieces = do From f6b12764e47b4bdd49ebefa91f1fa7712b837734 Mon Sep 17 00:00:00 2001 From: Kirilll Zaborsky Date: Tue, 9 Apr 2013 10:53:49 +0400 Subject: [PATCH 2/2] Added haddocks to setCreds/clearCreds --- yesod-auth/Yesod/Auth.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index 83ec6492..e398a84b 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -164,7 +164,11 @@ mkYesodSub "Auth" /page/#Text/STRINGS PluginR |] -setCreds :: YesodAuth master => Bool -> Creds master -> GHandler sub master () +-- | Sets user credentials for the session after checking them with authentication backends. +setCreds :: YesodAuth master + => Bool -- ^ if HTTP redirects should be done + -> Creds master -- ^ new credentials + -> GHandler sub master () setCreds doRedirects creds = do y <- getYesod maid <- getAuthId creds @@ -185,7 +189,10 @@ $newline never onLogin redirectUltDest $ loginDest y -clearCreds :: YesodAuth master => Bool -> GHandler sub master () +-- | Clears current user credentials for the session. +clearCreds :: YesodAuth master + => Bool -- ^ if HTTP redirect to 'logoutDest' should be done + -> GHandler sub master () clearCreds doRedirects = do y <- getYesod deleteSession credsKey