Skip to content

Commit

Permalink
Merge pull request jgm#528 from Rufflewind/github-login-failure-page
Browse files Browse the repository at this point in the history
Add page for login failure when authorization is required for reading
  • Loading branch information
jgm committed Dec 30, 2015
2 parents ff45b6d + ca4558c commit f04022e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Network/Gitit/Authentication.hs
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,33 @@ oauthGithubCallback ghConfig githubCallbackPars =
seeOther (encUrl destination) $ toResponse ()
Left err -> do
liftIO $ logM "gitit" WARNING $ "Login Failed: " ++ ghUserMessage err ++ maybe "" (". Github response" ++) (ghDetails err)
let url = destination ++ "?message=" ++ ghUserMessage err
cfg <- getConfig
let destination'
| requireAuthentication cfg >= ForRead = base' ++ "/_loginFailure"
| otherwise = destination
let url = destination' ++ "?message=" ++ ghUserMessage err
seeOther (encUrl url) $ toResponse ()

githubAuthHandlers :: GithubConfig
-> [Handler]
githubAuthHandlers ghConfig =
[ dir "_logout" $ withData logoutUser
, dir "_login" $ loginGithubUser $ oAuth2 ghConfig
, dir "_loginFailure" $ githubLoginFailure
, dir "_githubCallback" $ withData $ oauthGithubCallback ghConfig
, dir "_user" currentUser ]

githubLoginFailure :: Handler
githubLoginFailure = withData $ \params ->
formattedPage (pageLayout (pMessages params)) noHtml >>= forbidden
where
pageLayout msgs =
defaultPageLayout{ pgShowPageTools = False,
pgTabs = [],
pgTitle = "Login failure",
pgMessages = msgs
}

-- Login using RPX (see RPX development docs at https://rpxnow.com/docs)
loginRPXUser :: RPars -- ^ The parameters passed by the RPX callback call (after authentication has taken place
-> Handler
Expand Down

0 comments on commit f04022e

Please sign in to comment.