move institutional email check to overleaf-integration

GitOrigin-RevId: 3e08b1e86bb14d90115df5337cab5c36bb6a69fc
This commit is contained in:
Ersun Warncke 2019-10-24 08:48:37 -04:00 committed by sharelatex
parent 3be4883649
commit 9319229657
2 changed files with 7 additions and 21 deletions

View file

@ -1,7 +1,5 @@
let UserEmailsController
const AuthenticationController = require('../Authentication/AuthenticationController')
const Features = require('../../infrastructure/Features')
const InstitutionsAPI = require('../Institutions/InstitutionsAPI')
const UserGetter = require('./UserGetter')
const UserUpdater = require('./UserUpdater')
const EmailHelper = require('../Helpers/EmailHelper')
@ -40,13 +38,13 @@ function add(req, res, next) {
})
}
async function resendConfirmation(req, res, next) {
function resendConfirmation(req, res, next) {
const userId = AuthenticationController.getLoggedInUserId(req)
const email = EmailHelper.parseEmail(req.body.email)
if (!email) {
return res.sendStatus(422)
}
UserGetter.getUserByAnyEmail(email, { _id: 1 }, async function(error, user) {
UserGetter.getUserByAnyEmail(email, { _id: 1 }, function(error, user) {
if (error) {
return next(error)
}
@ -57,23 +55,6 @@ async function resendConfirmation(req, res, next) {
)
return res.sendStatus(422)
}
if (Features.hasFeature('saml') || req.session.samlBeta) {
// institution SSO emails cannot be confirmed by email,
// confirmation happens by linking to the institution
let institution
try {
institution = await InstitutionsAPI.getInstitutionViaDomain(
email.split('@').pop()
)
} catch (error) {
if (!(error instanceof Errors.NotFoundError)) {
throw error
}
}
if (institution && institution.sso_enabled) {
return res.sendStatus(422)
}
}
logger.log({ userId, email }, 'resending email confirmation token')
UserEmailsConfirmationHandler.sendConfirmationEmail(userId, email, function(
error

View file

@ -158,6 +158,11 @@ module.exports = class UserHelper {
if (body.message && body.message.type === 'error') {
throw new Error(`register api error: ${body.message.text}`)
}
if (body.redir === '/institutional-login') {
throw new Error(
`cannot register intitutional email: ${options.json.email}`
)
}
userHelper.user = await UserGetter.promises.getUser({
email: userData.email
})