Merge pull request #2690 from overleaf/ta-redirection-helper

Add RedirectionHelper

GitOrigin-RevId: 229ca78f26a9db205e23ecf91f85d6d1e926750a
This commit is contained in:
Timothée Alby 2020-04-01 10:07:44 -05:00 committed by Copybot
parent 05a2529881
commit fb2e182d2e
2 changed files with 18 additions and 12 deletions

View file

@ -14,6 +14,7 @@ const Analytics = require('../Analytics/AnalyticsManager')
const passport = require('passport')
const NotificationsBuilder = require('../Notifications/NotificationsBuilder')
const UrlHelper = require('../Helpers/UrlHelper')
const AsyncFormHelper = require('../Helpers/AsyncFormHelper')
const SudoModeHandler = require('../SudoMode/SudoModeHandler')
const _ = require('lodash')
@ -145,13 +146,7 @@ const AuthenticationController = (module.exports = {
)
}
AuthenticationController._clearRedirectFromSession(req)
if (
_.get(req, ['headers', 'accept'], '').match(/^application\/json.*$/)
) {
res.json({ redir })
} else {
res.redirect(redir)
}
AsyncFormHelper.redirect(req, res, redir)
})
})
})
@ -436,11 +431,7 @@ const AuthenticationController = (module.exports = {
)
req.session.reconfirm_email = user != null ? user.email : undefined
const redir = '/user/reconfirm'
if (_.get(req, ['headers', 'accept'], '').match(/^application\/json.*$/)) {
res.json({ redir })
} else {
res.redirect(redir)
}
AsyncFormHelper.redirect(req, res, redir)
},
_redirectToRegisterPage(req, res) {

View file

@ -0,0 +1,15 @@
const _ = require('lodash')
module.exports = {
redirect
}
// redirect the request via headers or JSON response depending on the request
// format
function redirect(req, res, redir) {
if (_.get(req, ['headers', 'accept'], '').match(/^application\/json.*$/)) {
res.json({ redir })
} else {
res.redirect(redir)
}
}