mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
3553fb2d9d
Fix spelling of "middleware" GitOrigin-RevId: d2b2b20ad8a6871cd6366303e75b340f0f2f2dda
25 lines
1 KiB
CoffeeScript
25 lines
1 KiB
CoffeeScript
logger = require 'logger-sharelatex'
|
|
SudoModeHandler = require './SudoModeHandler'
|
|
AuthenticationController = require '../Authentication/AuthenticationController'
|
|
Settings = require 'settings-sharelatex'
|
|
|
|
|
|
module.exports = SudoModeMiddleware =
|
|
|
|
protectPage: (req, res, next) ->
|
|
if req.externalAuthenticationSystemUsed() and !Settings.overleaf?
|
|
logger.log {userId}, "[SudoMode] using external auth, skipping sudo-mode check"
|
|
return 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')
|