From 833bdfa2aac6ac7519ce1a7e597ee9c8eaf31811 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 17 Sep 2017 11:09:19 +0300 Subject: [PATCH] Fix session data not updating correctly --- src/client.js | 9 ++++++--- src/clientManager.js | 2 +- src/server.js | 12 ------------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/client.js b/src/client.js index d4cd3ccc..a70b9472 100644 --- a/src/client.js +++ b/src/client.js @@ -304,11 +304,15 @@ Client.prototype.updateSession = function(token, ip, request) { 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(), ip: ip, agent: friendlyAgent, - }, client.config.sessions[token]); + }); + + client.manager.updateUser(client.name, { + sessions: client.config.sessions + }); }; Client.prototype.setPassword = function(hash, callback) { @@ -318,7 +322,6 @@ Client.prototype.setPassword = function(hash, callback) { password: hash }, function(err) { if (err) { - log.error("Failed to update password of", client.name, err); return callback(false); } diff --git a/src/clientManager.js b/src/clientManager.js index f8425182..da7f663d 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -153,7 +153,7 @@ ClientManager.prototype.updateUser = function(name, opts, callback) { fs.writeFile(Helper.getUserConfigPath(name), newUser, (err) => { if (err) { - log.error("Failed to update user", err); + log.error(`Failed to update user ${colors.green(name)} (${err})`); } if (callback) { diff --git a/src/server.js b/src/server.js index a5f58d3a..76e6ac2b 100644 --- a/src/server.js +++ b/src/server.js @@ -407,10 +407,6 @@ function initializeClient(socket, client, token, lastMessage) { client.manager.updateUser(client.name, { sessions: client.config.sessions - }, (err) => { - if (err) { - log.error("Failed to update sessions for", client.name, err); - } }); _.map(client.attachedClients, (attachedClient, socketId) => { @@ -461,14 +457,6 @@ function initializeClient(socket, client, token, lastMessage) { 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); }); } else {