Skip to content

Commit

Permalink
Update few changes
Browse files Browse the repository at this point in the history
  • Loading branch information
loay committed Sep 19, 2016
1 parent b2182eb commit e2e91dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
8 changes: 2 additions & 6 deletions common/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ module.exports = function(User) {
next();
});
});

UserModel.observe('after save', function afterEmailUpdate(ctx, next) {
if (!ctx.Model.relations.accessTokens) return next();
var AccessToken = ctx.Model.relations.accessTokens.modelTo;
Expand All @@ -697,14 +698,9 @@ module.exports = function(User) {
return u.id;
});
if (!idsToExpire.length) return next();
AccessToken.deleteAll({ userId: { inq: idsToExpire }}, function(err, info) {
if (err) return next();
next();
});
AccessToken.deleteAll({ userId: { inq: idsToExpire }}, next);
});



UserModel.remoteMethod(
'login',
{
Expand Down
27 changes: 9 additions & 18 deletions test/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ describe('User', function() {

describe('Email Update', function() {
describe('User changing email property', function() {
var user, originalUserToken1, originalUserToken2, newUserCreated, userSpecial, userNormal;
var user, originalUserToken1, originalUserToken2, newUserCreated;
var currentEmailCredentials = { email: '[email protected]', password: 'bar' };
var updatedEmailCredentials = { email: '[email protected]', password: 'bar' };
var newUserCred = { email: '[email protected]', password: 'newpass' };
Expand Down Expand Up @@ -1839,9 +1839,7 @@ describe('User', function() {
next();
});
},
], function(err) {
done(err);
});
], done);
});

it('invalidates sessions when email is changed using `updateAttributes`', function(done) {
Expand Down Expand Up @@ -1948,9 +1946,7 @@ describe('User', function() {
assertPreservedToken(next);
});
},
], function(err) {
done(err);
});
], done);
});

it('keeps sessions AS IS if a new user is created using `updateOrCreate`', function(done) {
Expand All @@ -1969,17 +1965,15 @@ describe('User', function() {
assertPreservedToken(next);
});
},
], function(err) {
done(err);
});
], done);
});

function assertPreservedToken(done) {
AccessToken.find({ where: { userId: user.id }}, function(err, tokens) {
if (err) return done(err);
expect(tokens.length).to.equal(2);
assert(originalUserToken1);
assert(originalUserToken2);
expect([tokens[0].id, tokens[1].id]).to.have.members([originalUserToken1,
originalUserToken2]);
done();
});
};
Expand Down Expand Up @@ -2060,13 +2054,12 @@ describe('User', function() {
});
});
},
], function(err) {
done(err);
});
], done);
});
});

it('invalidates sessions after using updateAll', function(done) {
var userSpecial, userNormal;
async.series([
function createSpecialUser(next) {
User.create(
Expand Down Expand Up @@ -2120,9 +2113,7 @@ describe('User', function() {
next();
});
},
], function(err) {
done(err);
});
], done);
});
});

Expand Down

0 comments on commit e2e91dc

Please sign in to comment.