Fix session data not updating correctly

This commit is contained in:
Pavel Djundik 2017-09-17 11:09:19 +03:00
parent d7e6db92b5
commit 833bdfa2aa
3 changed files with 7 additions and 16 deletions

View File

@ -304,11 +304,15 @@ Client.prototype.updateSession = function(token, ip, request) {
friendlyAgent += ` on ${agent.os.name} ${agent.os.version}`; friendlyAgent += ` on ${agent.os.name} ${agent.os.version}`;
} }
client.config.sessions[token] = _.assign({ client.config.sessions[token] = _.assign(client.config.sessions[token], {
lastUse: Date.now(), lastUse: Date.now(),
ip: ip, ip: ip,
agent: friendlyAgent, agent: friendlyAgent,
}, client.config.sessions[token]); });
client.manager.updateUser(client.name, {
sessions: client.config.sessions
});
}; };
Client.prototype.setPassword = function(hash, callback) { Client.prototype.setPassword = function(hash, callback) {
@ -318,7 +322,6 @@ Client.prototype.setPassword = function(hash, callback) {
password: hash password: hash
}, function(err) { }, function(err) {
if (err) { if (err) {
log.error("Failed to update password of", client.name, err);
return callback(false); return callback(false);
} }

View File

@ -153,7 +153,7 @@ ClientManager.prototype.updateUser = function(name, opts, callback) {
fs.writeFile(Helper.getUserConfigPath(name), newUser, (err) => { fs.writeFile(Helper.getUserConfigPath(name), newUser, (err) => {
if (err) { if (err) {
log.error("Failed to update user", err); log.error(`Failed to update user ${colors.green(name)} (${err})`);
} }
if (callback) { if (callback) {

View File

@ -407,10 +407,6 @@ function initializeClient(socket, client, token, lastMessage) {
client.manager.updateUser(client.name, { client.manager.updateUser(client.name, {
sessions: client.config.sessions sessions: client.config.sessions
}, (err) => {
if (err) {
log.error("Failed to update sessions for", client.name, err);
}
}); });
_.map(client.attachedClients, (attachedClient, socketId) => { _.map(client.attachedClients, (attachedClient, socketId) => {
@ -461,14 +457,6 @@ function initializeClient(socket, client, token, lastMessage) {
client.updateSession(token, getClientIp(socket.request), socket.request); client.updateSession(token, getClientIp(socket.request), socket.request);
client.manager.updateUser(client.name, {
sessions: client.config.sessions
}, (err) => {
if (err) {
log.error("Failed to update sessions for", client.name, err);
}
});
sendInitEvent(token); sendInitEvent(token);
}); });
} else { } else {