Move add email function

GitOrigin-RevId: f45e28a9ed357427ae606ad5f8b59acaef54e31b
This commit is contained in:
Jessica Lawshe 2019-10-04 12:42:07 -05:00 committed by sharelatex
parent 5c918bed94
commit de8ac8ace7

View file

@ -9,6 +9,35 @@ const logger = require('logger-sharelatex')
const Errors = require('../Errors/Errors')
const HttpErrors = require('@overleaf/o-error/http')
function add(req, res, next) {
const userId = AuthenticationController.getLoggedInUserId(req)
const email = EmailHelper.parseEmail(req.body.email)
if (!email) {
return res.sendStatus(422)
}
const affiliationOptions = {
university: req.body.university,
role: req.body.role,
department: req.body.department
}
UserUpdater.addEmailAddress(userId, email, affiliationOptions, function(
error
) {
if (error) {
return UserEmailsController._handleEmailError(error, req, res, next)
}
UserEmailsConfirmationHandler.sendConfirmationEmail(userId, email, function(
error
) {
if (error) {
return next(error)
}
res.sendStatus(204)
})
})
}
module.exports = UserEmailsController = {
list(req, res, next) {
const userId = AuthenticationController.getLoggedInUserId(req)
@ -20,36 +49,7 @@ module.exports = UserEmailsController = {
})
},
add(req, res, next) {
const userId = AuthenticationController.getLoggedInUserId(req)
const email = EmailHelper.parseEmail(req.body.email)
if (!email) {
return res.sendStatus(422)
}
const affiliationOptions = {
university: req.body.university,
role: req.body.role,
department: req.body.department
}
UserUpdater.addEmailAddress(userId, email, affiliationOptions, function(
error
) {
if (error) {
return UserEmailsController._handleEmailError(error, req, res, next)
}
UserEmailsConfirmationHandler.sendConfirmationEmail(
userId,
email,
function(error) {
if (error) {
return next(error)
}
res.sendStatus(204)
}
)
})
},
add,
remove(req, res, next) {
const userId = AuthenticationController.getLoggedInUserId(req)