feat(админка): сессии и сброс 2FA

This commit is contained in:
anor
2026-11-06 23:15:49 +10:00
parent 4051c9eb3d
commit 3596ff544c
7 changed files with 189 additions and 1 deletions
+25 -1
View File
@@ -11,6 +11,7 @@ const when = (ts) => new Date(ts * 1000).toLocaleString('ru-RU');
export function SystemPage() {
const [data, setData] = useState(null);
const [error, setError] = useState('');
const [sessions, setSessions] = useState([]);
useEffect(() => {
let alive = true;
@@ -18,7 +19,11 @@ export function SystemPage() {
if (alive) { setData(d); setError(''); }
}).catch((e) => { if (alive) setError(e.message || 'Система не отвечает'); });
load();
const t = setInterval(load, 60000);
const loadSessions = () => api('/api/admin/v2/sessions').then((d) => {
if (alive) setSessions(d.items || []);
}).catch(() => {});
loadSessions();
const t = setInterval(() => { load(); loadSessions(); }, 60000);
return () => { alive = false; clearInterval(t); };
}, []);
@@ -44,6 +49,25 @@ export function SystemPage() {
{key: 'key', label: 'Ключ'}, {key: 'value', label: 'Значение'},
]} rows=${data.settings.map((r) => ({...r, key: r.key}))} empty="Настроек нет" />
</section>
<section class="card">
<h2>Сессии</h2>
<div class="toolbar"><button type="button" onClick=${async () => {
await api('/api/admin/v2/sessions/revoke-all', {method: 'POST'});
setSessions([]); setError('Выйдите и войдите заново');
}}>Выйти на всех</button></div>
<${Table} columns=${[
{key: 'created_at', label: 'Начало', render: (r) => when(r.created_at)},
{key: 'ip', label: 'IP'}, {key: 'user_agent', label: 'Устройство'},
{key: 'current', label: 'Текущая', render: (r) => r.current ? 'да' : ''},
{key: 'active', label: 'Активна', render: (r) => r.active ? 'да' : 'нет'},
{key: 'act', label: '', render: (r) => html`<button type="button" disabled=${!r.active}
onClick=${async () => {
await api('/api/admin/v2/sessions/' + encodeURIComponent(r.jti) + '/revoke',
{method: 'POST'});
setSessions((xs) => xs.map((x) => x.jti === r.jti ? {...x, active: false} : x));
}}>Отозвать</button>`},
]} rows=${sessions.map((r) => ({...r, key: r.jti}))} empty="Сессий нет" />
</section>
<section class="card">
<h2>История</h2>
<${Table} columns=${[