0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

🔑 Expand subscriber email validation (#7793)

no issue

Expand the existing validation for subscriber email to not only check for the existence, but also if it's a valid email address. If it's not a valid email address, it will throw an error.

Credits: Eliran Itzhak & Shashank Kumar
This commit is contained in:
Aileen Nowak 2016-12-21 16:52:47 +07:00 committed by Katharina Irrgang
parent 1bc617174d
commit 5e253285bf

View file

@ -78,6 +78,8 @@ function storeSubscriber(req, res, next) {
if (_.isEmpty(req.body.email)) {
return next(new errors.ValidationError({message: 'Email cannot be blank.'}));
} else if (!validator.isEmail(req.body.email)) {
return next(new errors.ValidationError({message: 'Invalid email.'}));
}
return api.subscribers.add({subscribers: [req.body]}, {context: {external: true}})