mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
21 lines
842 B
CoffeeScript
21 lines
842 B
CoffeeScript
logger = require 'logger-sharelatex'
|
|
SudoModeHandler = require './SudoModeHandler'
|
|
AuthenticationController = require '../Authentication/AuthenticationController'
|
|
|
|
|
|
module.exports = SudoModeMiddlewear =
|
|
|
|
protectPage: (req, res, next) ->
|
|
userId = AuthenticationController.getLoggedInUserId(req)
|
|
logger.log {userId}, "[SudoMode] protecting endpoint, checking if sudo mode is active"
|
|
SudoModeHandler.isSudoModeActive userId, (err, isActive) ->
|
|
if err?
|
|
logger.err {err, userId}, "[SudoMode] error checking if sudo mode is active"
|
|
return next(err)
|
|
if isActive
|
|
logger.log {userId}, "[SudoMode] sudo mode active, continuing"
|
|
return next()
|
|
else
|
|
logger.log {userId}, "[SudoMode] sudo mode not active, redirecting"
|
|
AuthenticationController._setRedirectInSession(req)
|
|
return res.redirect('/confirm-password')
|