Node.js based forum software built for the modern web
closes #4950
Julian Lame26166a45b26
diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.jsonindex 319f5005b6..b6ddd1a2bb 100644--- a/public/language/en_GB/error.json+++ b/public/language/en_GB/error.json@@ -153,5 +153,8 @@"no-users-in-room": "No users in this room","cant-kick-self": "You can't kick yourself from the group","no-users-selected": "No user(s) selected",- "invalid-home-page-route": "Invalid home page route"+ "invalid-home-page-route": "Invalid home page route",++ "invalid-session": "Session Mismatch",+ "invalid-session-text": "It looks like your login session is no longer active, or no longer matches with the server. Please refresh this page."}diff --git a/public/src/app.js b/public/src/app.jsindex a913517363..ecb17de0c9 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -117,6 +117,10 @@ app.cacheBuster = null;};app.alertError = function (message, timeout) {+ if (message === '[[error:invalid-session]]') {+ return app.handleInvalidSession();+ }+app.alert({title: '[[global:alert.error]]',message: message,@@ -125,6 +129,28 @@ app.cacheBuster = null;});};+ app.handleInvalidSession = function() {+ if (app.flags && app.flags._sessionRefresh) {+ return;+ }++ app.flags = app.flags || {};+ app.flags._sessionRefresh = true;++ require(['translator'], function(translator) {+ translator.translate('[[error:invalid-session-text]]', function(translated) {+ bootbox.alert({+ title: '[[error:invalid-session]]',+ message: translated,+ closeButton: false,+ callback: function() {+ window.location.reload();+ }+ });+ });+ });+ };+app.enterRoom = function (room, callback) {callback = callback || function() {};if (socket && app.user.uid && app.currentRoom !== room) {diff --git a/public/src/sockets.js b/public/src/sockets.jsindex 461c148be7..f2a9bfd346 100644--- a/public/src/sockets.js+++ b/public/src/sockets.js@@ -28,6 +28,12 @@ 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)) {+ app.handleInvalidSession();+ }+ });+socket.on('event:banned', onEventBanned);socket.on('event:alert', app.alert);diff --git a/src/socket.io/index.js b/src/socket.io/index.jsindex cebbfe1a24..3ec75ecd0d 100644--- a/src/socket.io/index.js+++ b/src/socket.io/index.js@@ -56,6 +56,8 @@ var ratelimit = require('../middleware/ratelimit');} else {socket.join('online_guests');}++ io.sockets.sockets[socket.id].emit('checkSession', socket.uid);}function onMessage(socket, payload) {