Preserve the connection that called logoutAll.

This commit is contained in:
Emily Stark
2013-08-22 22:36:34 -07:00
parent 7dfff264a3
commit 3403b31c42
3 changed files with 33 additions and 9 deletions

View File

@@ -174,6 +174,18 @@ Meteor.logout = function (callback) {
});
};
Meteor._logoutAll = function (callback) {
Meteor.apply('_logoutAll', [], {wait: true}, function (error, result) {
if (error) {
callback && callback(error);
} else {
// The method should return a new valid token that we should start using.
makeClientLoggedIn(Meteor.userId(), result.token);
callback && callback();
}
});
};
///
/// LOGIN SERVICES
///

View File

@@ -89,9 +89,8 @@ Meteor.methods({
},
// Nuke everything: delete all the user's tokens and close all open
// connections logged in as this user. XXX Should eventually get a fresh new
// token on the connection that called it and not get closed.
logoutAll: function () {
// connections logged in as this user.
_logoutAll: function () {
var user = Meteor.users.findOne(this.userId);
if (user) {
var tokens = user.services.resume.loginTokens;
@@ -101,6 +100,15 @@ Meteor.methods({
this._closeAllForTokens(_.map(tokens, function (token) {
return token.token;
}));
var newToken = Accounts._generateStampedLoginToken();
Meteor.users.update(this.userId, {
$push: {
"services.resume.loginTokens": newToken
}
});
this._setLoginToken(newToken);
return newToken;
}
}
});

View File

@@ -599,7 +599,7 @@ _.extend(Session.prototype, {
};
var closeAll = function (tokens) {
self._closeAllForTokens(tokens);
self._closeAllForTokens(tokens, [self.id]);
};
var invocation = new MethodInvocation({
@@ -669,7 +669,7 @@ _.extend(Session.prototype, {
_closeAllForTokens: function (tokens) {
var self = this;
self.server._closeAllForTokens(tokens);
self.server._closeAllForTokens(tokens, [self.id]);
},
// Sets the current user id in all appropriate contexts and reruns
@@ -1356,14 +1356,18 @@ _.extend(Server.prototype, {
self.sessionsByLoginToken[newToken].push(session.id);
},
_closeAllForTokens: function (tokens) {
// Close all open sessions associated with any of the tokens in `tokens`,
// except for sessions with ids in `excludeSessions`.
_closeAllForTokens: function (tokens, excludeSessions) {
var self = this;
_.each(tokens, function (token) {
if (_.has(self.sessionsByLoginToken, token)) {
_.each(self.sessionsByLoginToken[token], function (sessionId) {
self.sessions[sessionId].cleanup();
self.sessions[sessionId].destroy();
delete self.sessions[sessionId];
if (_.indexOf(excludeSessions, sessionId) === -1) {
self.sessions[sessionId].cleanup();
self.sessions[sessionId].destroy();
delete self.sessions[sessionId];
}
});
}
});