Set redirect when redirecting from restricted

This commit is contained in:
Shane Kilkelly 2016-11-22 16:54:03 +00:00
parent 8089bb55a4
commit 8a4352fff2
3 changed files with 9 additions and 4 deletions

View file

@ -189,10 +189,11 @@ module.exports = AuthenticationController =
Metrics.inc "user.login.failed"
callback()
_setRedirectInSession: (req) ->
target = if Object.keys(req.query) then "#{req.path}?#{querystring.stringify(req.query)}" else req.path
_setRedirectInSession: (req, value) ->
if !value?
value = if Object.keys(req.query) > 0 then "#{req.path}?#{querystring.stringify(req.query)}" else req.path
if req.session?
req.session.postLoginRedirect = target
req.session.postLoginRedirect = value
_getRedirectFromSession: (req) ->
return req?.session?.postLoginRedirect || null

View file

@ -108,5 +108,5 @@ module.exports = AuthorizationMiddlewear =
logger.log {from: from}, "redirecting to login"
redirect_to = "/login"
if from?
redirect_to += "?redir=#{encodeURIComponent(from)}"
AuthenticationController._setRedirectInSession(req, from)
res.redirect redirect_to

View file

@ -541,6 +541,10 @@ describe "AuthenticationController", ->
@AuthenticationController._setRedirectInSession(@req)
expect(@req.session.postLoginRedirect).to.equal "/somewhere?one=1"
it 'should set the supplied value', ->
@AuthenticationController._setRedirectInSession(@req, '/somewhere/specific')
expect(@req.session.postLoginRedirect).to.equal "/somewhere/specific"
describe '_getRedirectFromSession', ->
beforeEach ->
@req = {session: {postLoginRedirect: "/a?b=c"}}