diff --git a/core/server/api/canary/settings.js b/core/server/api/canary/settings.js index 7a2f7bf073..60fdef2102 100644 --- a/core/server/api/canary/settings.js +++ b/core/server/api/canary/settings.js @@ -1,11 +1,10 @@ const Promise = require('bluebird'); const _ = require('lodash'); -const validator = require('@tryghost/validator'); const models = require('../../models'); const routeSettings = require('../../services/route-settings'); const frontendSettings = require('../../../frontend/services/settings'); const i18n = require('../../../shared/i18n'); -const {BadRequestError, NoPermissionError} = require('@tryghost/errors'); +const {BadRequestError} = require('@tryghost/errors'); const settingsService = require('../../services/settings'); const settingsCache = require('../../../shared/settings-cache'); const membersService = require('../../services/members'); @@ -121,17 +120,7 @@ module.exports = { ], async query(frame) { const {email, type} = frame.data; - if (typeof email !== 'string' || !validator.isEmail(email)) { - throw new BadRequestError({ - message: i18n.t('errors.api.settings.invalidEmailReceived') - }); - } - if (!type || !['fromAddressUpdate', 'supportAddressUpdate'].includes(type)) { - throw new BadRequestError({ - message: 'Invalid email type recieved' - }); - } try { // Send magic link to update fromAddress await membersService.settings.sendEmailAddressUpdateMagicLink({ diff --git a/core/server/api/canary/utils/validators/input/settings.js b/core/server/api/canary/utils/validators/input/settings.js index 4f9dcc4918..1679b911ea 100644 --- a/core/server/api/canary/utils/validators/input/settings.js +++ b/core/server/api/canary/utils/validators/input/settings.js @@ -1,7 +1,13 @@ const Promise = require('bluebird'); const _ = require('lodash'); const i18n = require('../../../../../../shared/i18n'); -const {NotFoundError, ValidationError} = require('@tryghost/errors'); +const {NotFoundError, ValidationError,BadRequestError} = require('@tryghost/errors'); +const validator = require('@tryghost/validator'); + +const messages = { + invalidEmailReceived: 'Please send a valid email', + invalidEmailTypeReceived: 'Invalid email type received' +}; module.exports = { read(apiConfig, frame) { @@ -62,5 +68,21 @@ module.exports = { if (errors.length) { return Promise.reject(errors[0]); } + }, + + updateMembersEmail(apiConfig, frame) { + const {email, type} = frame.data; + + if (typeof email !== 'string' || !validator.isEmail(email)) { + throw new BadRequestError({ + message: messages.invalidEmailReceived + }); + } + + if (!type || !['fromAddressUpdate', 'supportAddressUpdate'].includes(type)) { + throw new BadRequestError({ + message: messages.invalidEmailTypeReceived + }); + } } };