Skip to content

Commit 0caee53

Browse files
authored
Merge pull request #3072 from strongloop/backport/email-verified-fix
Fix false emailVerified on user model update
2 parents 6e3fc24 + 659e9ce commit 0caee53

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

common/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ module.exports = function(User) {
845845
if (emailChanged && ctx.Model.settings.emailVerificationRequired) {
846846
ctx.instance.emailVerified = false;
847847
}
848-
} else {
848+
} else if (ctx.data.email) {
849849
emailChanged = ctx.hookState.originalUserData.some(function(data) {
850850
return data.email != ctx.data.email;
851851
});

test/user.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,28 @@ describe('User', function() {
23582358
], done);
23592359
});
23602360

2361+
it('should not set verification to false after something other than email is updated',
2362+
function(done) {
2363+
User.settings.emailVerificationRequired = true;
2364+
async.series([
2365+
function updateUser(next) {
2366+
userInstance.updateAttribute('realm', 'test', function(err, info) {
2367+
if (err) return next(err);
2368+
assert.equal(info.realm, 'test');
2369+
next();
2370+
});
2371+
},
2372+
function findUser(next) {
2373+
User.findById(userInstance.id, function(err, info) {
2374+
if (err) return next(err);
2375+
assert.equal(info.realm, 'test');
2376+
assert.equal(info.emailVerified, true);
2377+
next();
2378+
});
2379+
},
2380+
], done);
2381+
});
2382+
23612383
function createOriginalUser(done) {
23622384
var userData = {
23632385

0 commit comments

Comments
 (0)