diff --git a/constants/error.constant.js b/constants/error.constant.js index 06ab069d..f2e6c535 100644 --- a/constants/error.constant.js +++ b/constants/error.constant.js @@ -9,6 +9,7 @@ const VOLUNTEER_404_MESSAGE = "Volunteer not found"; const SETTINGS_404_MESSAGE = "Settings not found"; const ACCOUNT_TYPE_409_MESSAGE = "Wrong account type"; +const ACCOUNT_EMAIL_409_MESSAGE = "Email already in use"; const SPONSOR_ID_409_MESSAGE = "Conflict with sponsor accountId link"; const VOLUNTEER_ID_409_MESSAGE = "Conflict with volunteer accountId link"; const HACKER_ID_409_MESSAGE = "Conflict with hacker accountId link"; @@ -50,6 +51,7 @@ module.exports = { TEAM_404_MESSAGE: TEAM_404_MESSAGE, RESUME_404_MESSAGE: RESUME_404_MESSAGE, ACCOUNT_TYPE_409_MESSAGE: ACCOUNT_TYPE_409_MESSAGE, + ACCOUNT_EMAIL_409_MESSAGE: ACCOUNT_EMAIL_409_MESSAGE, SPONSOR_ID_409_MESSAGE: SPONSOR_ID_409_MESSAGE, VOLUNTEER_ID_409_MESSAGE: VOLUNTEER_ID_409_MESSAGE, TEAM_MEMBER_409_MESSAGE: TEAM_MEMBER_409_MESSAGE, diff --git a/middlewares/account.middleware.js b/middlewares/account.middleware.js index bea0e578..38b14170 100644 --- a/middlewares/account.middleware.js +++ b/middlewares/account.middleware.js @@ -168,7 +168,17 @@ async function updateAccount(req, res, next) { // If we are changing the email, and there is a difference between the two, set back to unconfirmed status. // TODO: When pull request for parse patch refactor #546 hits, req.body.email will not be present. if (req.body.email && account.email != req.body.email) { - req.body.confirmed = false; + const existingAccount = await Services.Account.findByEmail( + account.email + ); + if (existingAccount) { + return next({ + status: 409, + message: Constants.Error.ACCOUNT_EMAIL_409_MESSAGE + }); + } else { + req.body.confirmed = false; + } } req.body.account = await Services.Account.updateOne( diff --git a/package-lock.json b/package-lock.json index 6b6ce283..1b488cd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5457,11 +5457,6 @@ "resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz", "integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y=" }, - "lodash.clonedeep": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" - }, "lodash.has": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz", @@ -6289,11 +6284,6 @@ "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, - "nvm": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/nvm/-/nvm-0.0.4.tgz", - "integrity": "sha1-OKF46dMbKDUIyS0VydqGHRqSELw=" - }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",