From e2b40ddf34277ebc0aa867fa9bfbc72b5b369384 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 23 Aug 2017 15:11:10 -0400 Subject: [PATCH] fixes #5894 --- public/src/sockets.js | 6 ++++-- src/socket.io/index.js | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/public/src/sockets.js b/public/src/sockets.js index 6b11f49e4f..7d7fca3d9f 100644 --- a/public/src/sockets.js +++ b/public/src/sockets.js @@ -28,9 +28,11 @@ app.isConnected = false; setTimeout(socket.connect.bind(socket), parseInt(config.reconnectionDelay, 10) * 10); }); - socket.on('checkSession', function (uid) { - if (parseInt(uid, 10) !== parseInt(app.user.uid, 10)) { + socket.on('checkSession', function (uid, remoteExist) { + if (parseInt(uid, 10) !== parseInt(app.user.uid, 10) && remoteExist) { app.handleInvalidSession(); + } else { + app.logout(); } }); diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 2e897d0c4c..c2615e281d 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -75,15 +75,17 @@ function onConnection(socket) { } function onConnect(socket) { - if (socket.uid) { - socket.join('uid_' + socket.uid); - socket.join('online_users'); - } else { - socket.join('online_guests'); - } + user.exists(socket.uid, function (err, exists) { + if (socket.uid) { + socket.join('uid_' + socket.uid); + socket.join('online_users'); + } else { + socket.join('online_guests'); + } - socket.join('sess_' + socket.request.signedCookies[nconf.get('sessionKey')]); - io.sockets.sockets[socket.id].emit('checkSession', socket.uid); + socket.join('sess_' + socket.request.signedCookies[nconf.get('sessionKey')]); + io.sockets.sockets[socket.id].emit('checkSession', socket.uid, exists); + }); } function onMessage(socket, payload) {