0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🐛 fix email already in use (#7987)

refs #7981

- usage of data.id was wrong
- usage of id comparison was wrong
This commit is contained in:
Katharina Irrgang 2017-02-13 16:36:21 +01:00 committed by Kevin Ansfield
parent d9e87aa793
commit 2a5927b4f9
2 changed files with 12 additions and 12 deletions

View file

@ -368,11 +368,10 @@ User = ghostBookshelf.Model.extend({
options = options || {}; options = options || {};
options.withRelated = _.union(options.withRelated, options.include); options.withRelated = _.union(options.withRelated, options.include);
if (data.email && data.id) { if (data.email) {
ops.push(function checkForDuplicateEmail() { ops.push(function checkForDuplicateEmail() {
return self.getByEmail(data.email).then(function then(user) { return self.getByEmail(data.email).then(function then(user) {
// don't allow update if another user already uses this email if (user && user.id !== options.id) {
if (user && user.id !== data.id) {
return Promise.reject(new errors.ValidationError({message: i18n.t('errors.models.user.userUpdateError.emailIsAlreadyInUse')})); return Promise.reject(new errors.ValidationError({message: i18n.t('errors.models.user.userUpdateError.emailIsAlreadyInUse')}));
} }
}); });

View file

@ -416,14 +416,15 @@ describe('User Model', function run() {
}); });
it('can NOT set an already existing email address', function (done) { it('can NOT set an already existing email address', function (done) {
var firstUser = testUtils.DataGenerator.Content.users[0].id, var firstUser = testUtils.DataGenerator.Content.users[0],
secondEmail = testUtils.DataGenerator.Content.users[1].email; secondUser = testUtils.DataGenerator.Content.users[1];
UserModel.findOne({id: firstUser}).then(function (user) { UserModel.edit({email: secondUser.email}, {id: firstUser.id})
return user.edit({email: secondEmail}); .then(function () {
}).then(function () {
done(new Error('Already existing email address was accepted')); done(new Error('Already existing email address was accepted'));
}).catch(function () { })
.catch(function (err) {
(err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });