mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: change the client side reloginTimer to match setting
when setting is changed restart timer closes #13561
This commit is contained in:
@@ -9,43 +9,12 @@ require('../../scripts-admin');
|
|||||||
app.onDomReady();
|
app.onDomReady();
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
let logoutTimer = 0;
|
require(['hooks', 'admin/settings', 'admin/modules/relogin-timer'], (hooks, Settings, reloginTimer) => {
|
||||||
let logoutMessage;
|
|
||||||
function startLogoutTimer() {
|
|
||||||
if (app.config.adminReloginDuration <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (logoutTimer) {
|
|
||||||
clearTimeout(logoutTimer);
|
|
||||||
}
|
|
||||||
// pre-translate language string gh#9046
|
|
||||||
if (!logoutMessage) {
|
|
||||||
require(['translator'], function (translator) {
|
|
||||||
translator.translate('[[login:logged-out-due-to-inactivity]]', function (translated) {
|
|
||||||
logoutMessage = translated;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
logoutTimer = setTimeout(function () {
|
|
||||||
require(['bootbox'], function (bootbox) {
|
|
||||||
bootbox.alert({
|
|
||||||
closeButton: false,
|
|
||||||
message: logoutMessage,
|
|
||||||
callback: function () {
|
|
||||||
window.location.reload();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, 3600000);
|
|
||||||
}
|
|
||||||
|
|
||||||
require(['hooks', 'admin/settings'], (hooks, Settings) => {
|
|
||||||
hooks.on('action:ajaxify.end', (data) => {
|
hooks.on('action:ajaxify.end', (data) => {
|
||||||
updatePageTitle(data.url);
|
updatePageTitle(data.url);
|
||||||
setupRestartLinks();
|
setupRestartLinks();
|
||||||
showCorrectNavTab();
|
showCorrectNavTab();
|
||||||
startLogoutTimer();
|
reloginTimer.start(app.config.adminReloginDuration);
|
||||||
|
|
||||||
$('[data-bs-toggle="tooltip"]').tooltip({
|
$('[data-bs-toggle="tooltip"]').tooltip({
|
||||||
animation: false,
|
animation: false,
|
||||||
@@ -59,6 +28,7 @@ app.onDomReady();
|
|||||||
Settings.populateTOC();
|
Settings.populateTOC();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.on('action:ajaxify.start', function () {
|
hooks.on('action:ajaxify.start', function () {
|
||||||
require(['bootstrap'], function (boostrap) {
|
require(['bootstrap'], function (boostrap) {
|
||||||
const offcanvas = boostrap.Offcanvas.getInstance('#offcanvas');
|
const offcanvas = boostrap.Offcanvas.getInstance('#offcanvas');
|
||||||
|
|||||||
36
public/src/admin/modules/relogin-timer.js
Normal file
36
public/src/admin/modules/relogin-timer.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { translate } from 'translator';
|
||||||
|
import { alert as bootboxAlert } from 'bootbox';
|
||||||
|
|
||||||
|
let logoutTimer = 0;
|
||||||
|
let logoutMessage;
|
||||||
|
|
||||||
|
export function start(adminReloginDuration) {
|
||||||
|
clearTimer();
|
||||||
|
if (adminReloginDuration <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pre-translate language string gh#9046
|
||||||
|
if (!logoutMessage) {
|
||||||
|
translate('[[login:logged-out-due-to-inactivity]]', function (translated) {
|
||||||
|
logoutMessage = translated;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeoutMs = adminReloginDuration * 60000;
|
||||||
|
logoutTimer = setTimeout(function () {
|
||||||
|
bootboxAlert({
|
||||||
|
closeButton: false,
|
||||||
|
message: logoutMessage,
|
||||||
|
callback: function () {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, timeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearTimer() {
|
||||||
|
if (logoutTimer) {
|
||||||
|
clearTimeout(logoutTimer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
|
|
||||||
define('admin/settings', [
|
define('admin/settings', [
|
||||||
'uploader', 'mousetrap', 'hooks', 'alerts', 'settings', 'bootstrap',
|
'uploader', 'mousetrap', 'hooks', 'alerts', 'settings', 'bootstrap', 'admin/modules/relogin-timer',
|
||||||
], function (uploader, mousetrap, hooks, alerts, settings, bootstrap) {
|
], function (uploader, mousetrap, hooks, alerts, settings, bootstrap, reloginTimer) {
|
||||||
const Settings = {};
|
const Settings = {};
|
||||||
|
|
||||||
Settings.populateTOC = function () {
|
Settings.populateTOC = function () {
|
||||||
@@ -217,6 +217,9 @@ define('admin/settings', [
|
|||||||
|
|
||||||
for (const [field, value] of Object.entries(data)) {
|
for (const [field, value] of Object.entries(data)) {
|
||||||
app.config[field] = value;
|
app.config[field] = value;
|
||||||
|
if (field === 'adminReloginDuration') {
|
||||||
|
reloginTimer.start(parseInt(value, 10));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user