diff --git a/public/src/app.js b/public/src/app.js index 86cc0bc11d..d6f34dc2d3 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -212,39 +212,6 @@ app.cacheBuster = null; }); }; - app.handleInvalidSession = function () { - socket.disconnect(); - app.logout(false); - require(['bootbox'], function (bootbox) { - bootbox.alert({ - title: '[[error:invalid-session]]', - message: '[[error:invalid-session-text]]', - closeButton: false, - callback: function () { - window.location.reload(); - }, - }); - }); - }; - - app.handleSessionMismatch = () => { - if (app.flags._login || app.flags._logout) { - return; - } - - socket.disconnect(); - require(['bootbox'], function (bootbox) { - bootbox.alert({ - title: '[[error:session-mismatch]]', - message: '[[error:session-mismatch-text]]', - 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/modules/messages.js b/public/src/modules/messages.js index ad8992a893..0c1cfe2e71 100644 --- a/public/src/modules/messages.js +++ b/public/src/modules/messages.js @@ -1,6 +1,6 @@ 'use strict'; -define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, translator, storage) { +define('messages', ['bootbox', 'translator', 'storage', 'alerts'], function (bootbox, translator, storage, alerts) { const messages = {}; let showWelcomeMessage; @@ -81,7 +81,7 @@ define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, tran registerMessage = params.register; if (showWelcomeMessage) { - app.alert({ + alerts.alert({ type: 'success', title: '[[global:welcome_back]] ' + app.user.username + '!', message: '[[global:you_have_successfully_logged_in]]', @@ -96,5 +96,27 @@ define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, tran } } + messages.showInvalidSession = function () { + bootbox.alert({ + title: '[[error:invalid-session]]', + message: '[[error:invalid-session-text]]', + closeButton: false, + callback: function () { + window.location.reload(); + }, + }); + }; + + messages.showSessionMismatch = function () { + bootbox.alert({ + title: '[[error:session-mismatch]]', + message: '[[error:session-mismatch-text]]', + closeButton: false, + callback: function () { + window.location.reload(); + }, + }); + }; + return messages; }); diff --git a/public/src/sockets.js b/public/src/sockets.js index 7615fe5b2b..c4763b28d5 100644 --- a/public/src/sockets.js +++ b/public/src/sockets.js @@ -80,11 +80,11 @@ socket = window.socket; socket.on('checkSession', function (uid) { if (parseInt(uid, 10) !== parseInt(app.user.uid, 10)) { - app.handleSessionMismatch(); + handleSessionMismatch(); } }); socket.on('event:invalid_session', () => { - app.handleInvalidSession(); + handleInvalidSession(); }); socket.on('setHostname', function (hostname) { @@ -126,6 +126,25 @@ socket = window.socket; }); } + function handleInvalidSession() { + socket.disconnect(); + app.logout(false); + require(['messages'], function (messages) { + messages.showInvalidSession(); + }); + } + + function handleSessionMismatch() { + if (app.flags._login || app.flags._logout) { + return; + } + + socket.disconnect(); + require(['messages'], function (messages) { + messages.showSessionMismatch(); + }); + } + function onConnect() { if (!reconnecting) { hooks.fire('action:connected');