Merge pull request #365 from sharelatex/bg-redirect-to-login-on-403

redirect to login on 403
This commit is contained in:
Brian Gough 2016-11-07 14:44:08 +00:00 committed by GitHub
commit f77ee597f4
4 changed files with 27 additions and 4 deletions

View file

@ -24,7 +24,7 @@ div.full-size(
keybindings="settings.mode",
font-size="settings.fontSize",
auto-complete="settings.autoComplete",
spell-check="true",
spell-check="!anonymous",
spell-check-language="project.spellCheckLanguage",
highlights="onlineUserCursorHighlights[editor.open_doc_id]"
show-print-margin="false",

View file

@ -24,8 +24,10 @@ define [
scope[attrs.name].inflight = true
# for asyncForm prevent automatic redirect to /login if
# authentication fails, we will handle it ourselves
$http
.post(element.attr('action'), formData)
.post(element.attr('action'), formData, {disableAutoLoginRedirect: true})
.success (data, status, headers, config) ->
scope[attrs.name].inflight = false
response.success = true

View file

@ -57,6 +57,7 @@ define [
"Content-Type": 'application/json'
data:
password: $scope.state.password
disableAutoLoginRedirect: true # we want to handle errors ourselves
})
.success () ->
$modalInstance.close()

View file

@ -9,6 +9,26 @@ app.config ['$provide', ($provide) ->
]
]
# TODO: add support for an errorHttpInterceptor to catch failing ajax
# requests as described at
# Interceptor to check auth failures in all $http requests
# http://bahmutov.calepin.co/catch-all-errors-in-angular-app.html
app.factory 'unAuthHttpResponseInterceptor', ['$q','$location', ($q, $location) ->
responseError: (response) ->
# redirect any unauthorised or forbidden responses back to /login
#
# set disableAutoLoginRedirect:true in the http request config
# to disable this behaviour
if response.status in [401, 403] and not response.config?.disableAutoLoginRedirect
# for /project urls set the ?redir parameter to come back here
# otherwise just go to the login page
if window.location.pathname.match(/^\/project/)
window.location = "/login?redir=#{encodeURI(window.location.pathname)}"
else
window.location = "/login"
# pass the response back to the original requester
return $q.reject(response)
]
app.config ['$httpProvider', ($httpProvider) ->
$httpProvider.interceptors.push 'unAuthHttpResponseInterceptor'
]