Merge pull request #3053 from yumenohosi/fix/email-verified

Fix false emailVerified on user model update
This commit is contained in:
Miroslav Bajtoš 2017-01-05 11:02:54 +01:00 committed by GitHub
commit f4b167698a
2 changed files with 23 additions and 1 deletions

View File

@ -858,7 +858,7 @@ module.exports = function(User) {
if (emailChanged && ctx.Model.settings.emailVerificationRequired) {
ctx.instance.emailVerified = false;
}
} else {
} else if (ctx.data.email) {
var emailChanged = ctx.hookState.originalUserData.some(function(data) {
return data.email != ctx.data.email;
});

View File

@ -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',