관리자 세션 해제 시 런처 일반 화면 전환
This commit is contained in:
+23
-2
@@ -1,5 +1,6 @@
|
||||
const shortcut = document.getElementById('findMyShortcut');
|
||||
let failIndex = 0;
|
||||
let lastRenderedAdmin = null;
|
||||
|
||||
const apiUrl = '/custom/launcher/api.php';
|
||||
const PIN_LENGTH = 4;
|
||||
@@ -83,6 +84,7 @@ async function renderIcons() {
|
||||
}
|
||||
|
||||
const isAdmin = !!session.admin;
|
||||
lastRenderedAdmin = isAdmin;
|
||||
const items = isAdmin ? adminIconItems : userIconItems;
|
||||
shortcut.className = `find-container ${isAdmin ? 'launcher-admin-grid' : ''}`;
|
||||
shortcut.innerHTML = '';
|
||||
@@ -119,8 +121,12 @@ async function renderIcons() {
|
||||
}
|
||||
|
||||
async function hasAdminSession() {
|
||||
const session = await getSession();
|
||||
return !!session.admin;
|
||||
try {
|
||||
const session = await fetch(`${apiUrl}?adminSession=1`, { credentials: 'same-origin' }).then(res => res.json());
|
||||
return !!session.admin;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function getSession() {
|
||||
@@ -149,6 +155,21 @@ async function requireAccess(nextAction) {
|
||||
showPasswordForm(nextAction);
|
||||
}
|
||||
|
||||
async function refreshAdminModeIfNeeded() {
|
||||
if (lastRenderedAdmin !== true) return;
|
||||
const isAdmin = await hasAdminSession();
|
||||
if (!isAdmin) {
|
||||
await renderIcons();
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (!document.hidden) {
|
||||
refreshAdminModeIfNeeded();
|
||||
}
|
||||
});
|
||||
window.addEventListener('focus', refreshAdminModeIfNeeded);
|
||||
|
||||
function renderLoginBlocked(session = {}) {
|
||||
shortcut.className = 'launcher-blocked';
|
||||
shortcut.innerHTML = '';
|
||||
|
||||
Reference in New Issue
Block a user