mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
refactor: move session messages
This commit is contained in:
@@ -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) {
|
app.enterRoom = function (room, callback) {
|
||||||
callback = callback || function () { };
|
callback = callback || function () { };
|
||||||
if (socket && app.user.uid && app.currentRoom !== room) {
|
if (socket && app.user.uid && app.currentRoom !== room) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, translator, storage) {
|
define('messages', ['bootbox', 'translator', 'storage', 'alerts'], function (bootbox, translator, storage, alerts) {
|
||||||
const messages = {};
|
const messages = {};
|
||||||
|
|
||||||
let showWelcomeMessage;
|
let showWelcomeMessage;
|
||||||
@@ -81,7 +81,7 @@ define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, tran
|
|||||||
registerMessage = params.register;
|
registerMessage = params.register;
|
||||||
|
|
||||||
if (showWelcomeMessage) {
|
if (showWelcomeMessage) {
|
||||||
app.alert({
|
alerts.alert({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
title: '[[global:welcome_back]] ' + app.user.username + '!',
|
title: '[[global:welcome_back]] ' + app.user.username + '!',
|
||||||
message: '[[global:you_have_successfully_logged_in]]',
|
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;
|
return messages;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -80,11 +80,11 @@ socket = window.socket;
|
|||||||
|
|
||||||
socket.on('checkSession', function (uid) {
|
socket.on('checkSession', function (uid) {
|
||||||
if (parseInt(uid, 10) !== parseInt(app.user.uid, 10)) {
|
if (parseInt(uid, 10) !== parseInt(app.user.uid, 10)) {
|
||||||
app.handleSessionMismatch();
|
handleSessionMismatch();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.on('event:invalid_session', () => {
|
socket.on('event:invalid_session', () => {
|
||||||
app.handleInvalidSession();
|
handleInvalidSession();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('setHostname', function (hostname) {
|
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() {
|
function onConnect() {
|
||||||
if (!reconnecting) {
|
if (!reconnecting) {
|
||||||
hooks.fire('action:connected');
|
hooks.fire('action:connected');
|
||||||
|
|||||||
Reference in New Issue
Block a user