diff --git a/src/client.js b/src/client.js index b7e69b10..f7dffa1f 100644 --- a/src/client.js +++ b/src/client.js @@ -316,6 +316,7 @@ Client.prototype.updateSession = function(token, ip, request) { }); client.manager.updateUser(client.name, { + browser: client.config.browser, sessions: client.config.sessions, }); }; diff --git a/src/clientManager.js b/src/clientManager.js index 4dc05385..e84ed37b 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -190,8 +190,10 @@ ClientManager.prototype.updateUser = function(name, opts, callback) { _.assign(user, opts); const newUser = JSON.stringify(user, null, "\t"); + // Do not touch the disk if object has not changed if (currentUser === newUser) { + console.log("same"); return callback ? callback() : true; } diff --git a/src/server.js b/src/server.js index 68d53d34..bf1185e4 100644 --- a/src/server.js +++ b/src/server.js @@ -664,15 +664,19 @@ function initializeClient(socket, client, token, lastMessage, openChannel) { socket.emit("commands", inputs.getCommands()); }; - if (!Helper.config.public && token === null) { + if (Helper.config.public) { + sendInitEvent(null); + } else if (token === null) { client.generateToken((newToken) => { - client.attachedClients[socket.id].token = token = client.calculateTokenHash(newToken); + token = client.calculateTokenHash(newToken); + client.attachedClients[socket.id].token = token; client.updateSession(token, getClientIp(socket), socket.request); sendInitEvent(newToken); }); } else { + client.updateSession(token, getClientIp(socket), socket.request); sendInitEvent(null); } } @@ -734,16 +738,9 @@ function performAuthentication(data) { let client; let token = null; - const finalInit = () => { + const finalInit = () => initializeClient(socket, client, token, data.lastMessage || -1, data.openChannel); - if (!Helper.config.public) { - client.manager.updateUser(client.name, { - browser: client.config.browser, - }); - } - }; - const initClient = () => { // Configuration does not change during runtime of TL, // and the client listens to this event only once @@ -827,8 +824,6 @@ function performAuthentication(data) { if (Object.prototype.hasOwnProperty.call(client.config.sessions, providedToken)) { token = providedToken; - client.updateSession(providedToken, getClientIp(socket), socket.request); - return authCallback(true); } }