diff --git a/common/models/user.js b/common/models/user.js index 7d488aed..7d5913df 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -860,7 +860,7 @@ module.exports = function(User) { } } else { var emailChanged = ctx.hookState.originalUserData.some(function(data) { - return data.email != ctx.data.email; + return ctx.data.email && data.email != ctx.data.email; }); if (emailChanged && ctx.Model.settings.emailVerificationRequired) { ctx.data.emailVerified = false; diff --git a/test/user.test.js b/test/user.test.js index 915bf0c2..17dec9d4 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -2315,6 +2315,28 @@ describe('User', function() { ], done); }); + it('should not set verification to false after something other than email is updated', + function(done) { + User.settings.emailVerificationRequired = true; + async.series([ + function updateUser(next) { + userInstance.updateAttribute('realm', 'test', function(err, info) { + if (err) return next (err); + assert.equal(info.realm, 'test'); + next(); + }); + }, + function findUser(next) { + User.findById(userInstance.id, function(err, info) { + if (err) return next (err); + assert.equal(info.realm, 'test'); + assert.equal(info.emailVerified, true); + next(); + }); + }, + ], done); + }); + function createOriginalUser(done) { var userData = { email: 'original@example.com',