mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #2690 from overleaf/ta-redirection-helper
Add RedirectionHelper GitOrigin-RevId: 229ca78f26a9db205e23ecf91f85d6d1e926750a
This commit is contained in:
parent
05a2529881
commit
fb2e182d2e
2 changed files with 18 additions and 12 deletions
|
@ -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) {
|
||||
|
|
15
services/web/app/src/Features/Helpers/AsyncFormHelper.js
Normal file
15
services/web/app/src/Features/Helpers/AsyncFormHelper.js
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue