Skip to content

Commit 659e9ce

Browse files
yumenohosibajtos
authored andcommitted
Fix false emailVerified on user model update
We noticed that every time the user model updates, the emailVerified column would change to false, even though the email was not changed at all. I took a look and realized there might be an error in eb640d8 The intent of the commit just mention is to make emailVerified false when the email gets changed, but notice that ctx.data.email is null on updates, so the condition is always met and emailVerified always becomes false. This commit fixes the issue just mentioned.
1 parent 6e3fc24 commit 659e9ce

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)