feat: a device can skip the PIN for 5, 15, 30 or 60 minutes after it was entered (off by default, this browser only)

This commit is contained in:
redtea committed 2026-10-14 21:13:50 +03:00
1 parent 119b524825
commit 5a204ae9bb
3 files changed
+36 -1

No files matched your search

+17
View File
@@ -2,16 +2,32 @@
// before showing anything. The tab remembers it was unlocked (sessionStorage
// lives as long as the tab, through reloads, and a new tab starts empty), so
// a reload does not ask again. Loaded in <head>, before the page shows.
// A device can be set to trust the PIN for a while: for that many minutes
// after it was entered, new tabs there open without asking (localStorage,
// this browser only).
(function () {
'use strict';
var KEY = 'lpra.pin.ok';
var ok = false;
try { ok = sessionStorage.getItem(KEY) === '1'; } catch (e) { /* no storage: ask */ }
if (ok) return;
try {
if (Date.now() < Number(localStorage.getItem('lpra.pin.until') || 0)) {
sessionStorage.setItem(KEY, '1');
return;
}
} catch (e) { /* ask */ }
var root = document.documentElement;
root.classList.add('pin-wait');
function release() { root.classList.remove('pin-wait'); }
function remember() { try { sessionStorage.setItem(KEY, '1'); } catch (e) { /* asked again next load */ } }
// After the PIN itself: no asking on this device for the minutes it trusts.
function trust() {
try {
var min = Number(localStorage.getItem('lpra.pin.grace') || 0);
if (min > 0) localStorage.setItem('lpra.pin.until', String(Date.now() + min * 60000));
} catch (e) { /* asks every tab */ }
}
fetch('/api/panel/pin', {cache: 'no-store'})
.then(function (r) { return r.ok ? r.json() : {pin: false}; })
@@ -67,6 +83,7 @@
.then(function (r) {
if (r.ok) {
remember();
trust();
box.classList.add('done');
release();
setTimeout(function () { box.remove(); }, 320);