From cc9791d3f452904e239e2464f56bfc5e290372cf Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 13 Sep 2016 11:23:47 +0100 Subject: [PATCH] Redirect to login with a redirect back to the page we want if not logged in --- .../Authorization/AuthorizationMiddlewear.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee b/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee index 4888db0c8a..7f2f67e03c 100644 --- a/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee +++ b/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee @@ -99,13 +99,17 @@ module.exports = AuthorizationMiddlewear = callback null, user_id redirectToRestricted: (req, res, next) -> - res.redirect "/restricted" + res.redirect "/restricted?from=#{encodeURIComponent(req.url)}" restricted : (req, res, next)-> if req.session.user? res.render 'user/restricted', title:'restricted' else - logger.log "user not logged in and trying to access #{req.url}, being redirected to login" - res.redirect '/register' + from = req.query.from + logger.log {from: from}, "redirecting to login" + redirect_to = "/login" + if from? + redirect_to += "?redir=#{encodeURIComponent(from)}" + res.redirect redirect_to \ No newline at end of file