diff --git a/services/web/app/src/Features/User/UserEmailsController.js b/services/web/app/src/Features/User/UserEmailsController.js index 9fbc1330fa..b6dea95519 100644 --- a/services/web/app/src/Features/User/UserEmailsController.js +++ b/services/web/app/src/Features/User/UserEmailsController.js @@ -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)