Redirect to login with a redirect back to the page we want if not logged in

This commit is contained in:
James Allen 2016-09-13 11:23:47 +01:00
parent 1714b014bf
commit cc9791d3f4

View file

@ -99,13 +99,17 @@ module.exports = AuthorizationMiddlewear =
callback null, user_id callback null, user_id
redirectToRestricted: (req, res, next) -> redirectToRestricted: (req, res, next) ->
res.redirect "/restricted" res.redirect "/restricted?from=#{encodeURIComponent(req.url)}"
restricted : (req, res, next)-> restricted : (req, res, next)->
if req.session.user? if req.session.user?
res.render 'user/restricted', res.render 'user/restricted',
title:'restricted' title:'restricted'
else else
logger.log "user not logged in and trying to access #{req.url}, being redirected to login" from = req.query.from
res.redirect '/register' logger.log {from: from}, "redirecting to login"
redirect_to = "/login"
if from?
redirect_to += "?redir=#{encodeURIComponent(from)}"
res.redirect redirect_to