mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
LOGOUT_WITH_TIMER ends a login at a deadline however busy its user is; nothing ended a session somebody walked away from. LOGOUT_IDLE_MINUTES (Admin Panel / People / Login, every platform; empty or 0 is off) does: the browser reports a key press, click, touch or scroll at most once a minute, the server keeps the time per login token in idleSessions, and once a minute every token idle past the limit is removed, which signs its connections out. A tab that reconnects and resumes its login by itself - a laptop waking up - is not activity and does not extend the session. REST API tokens have no session record and are never removed. The time is kept beside the user rather than on the token, because updating one element of the token array needs the positional $ operator, which not every database WeKan runs on supports. Thanks to xet7 !
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
// LOGOUT_IDLE_MINUTES: tell the server, at most once a minute, that the user
|
|
// did something here - a key press, a click, a touch, a scroll - so a session
|
|
// in use is not signed out as idle (models/lib/idleLogout.js). Nothing is sent
|
|
// while the page only sits open, and nothing at all when the limit is off.
|
|
|
|
const { TOUCH_INTERVAL_MS } = require('../../models/lib/idleLogout');
|
|
|
|
const EVENTS = ['keydown', 'mousedown', 'touchstart', 'wheel', 'scroll'];
|
|
|
|
// target: where to listen (document); touch(): report; now(): clock.
|
|
function createIdleActivityReporter({ target, touch, now = () => Date.now(), interval = TOUCH_INTERVAL_MS }) {
|
|
let last = 0;
|
|
let listening = false;
|
|
function onActivity() {
|
|
const t = now();
|
|
if (t - last < interval) return;
|
|
last = t;
|
|
touch();
|
|
}
|
|
return {
|
|
start() {
|
|
if (listening) return;
|
|
listening = true;
|
|
last = now(); // signing in was the activity that started this
|
|
for (const name of EVENTS) target.addEventListener(name, onActivity, { capture: true, passive: true });
|
|
},
|
|
stop() {
|
|
if (!listening) return;
|
|
listening = false;
|
|
for (const name of EVENTS) target.removeEventListener(name, onActivity, { capture: true });
|
|
},
|
|
onActivity,
|
|
};
|
|
}
|
|
|
|
module.exports = { createIdleActivityReporter, EVENTS };
|