Show management only to site admins

This commit is contained in:
seo
2026-06-12 15:38:09 +09:00
parent 8145dc6938
commit baeccf9d58
3 changed files with 21 additions and 3 deletions
+3 -2
View File
@@ -17,10 +17,11 @@
- 차량 모니터 이동
- 공통 암호 로그인
- 공통 암호 변경
- 사이트 관리자 로그인 상태에서만 관리 버튼 표시
## 구조
- `api.php`: 로그인, 로그아웃, 암호 변경, 콕 찌르기 카운트/웹훅 처리
- `api.php`: 로그인, 로그아웃, 암호 변경, 관리자 세션 확인, 콕 찌르기 카운트/웹훅 처리
- `js/main.js`: 4개 아이콘 렌더링, 인증 흐름, 암호 변경 UI
- `css/style.css`: 기존 삽입 코드 호환용 공용 CSS import
- `img/`: 런처 아이콘 이미지
@@ -33,4 +34,4 @@
## 운영 메모
메인 버튼은 기존 4개를 유지합니다. 암호 변경은 배너 우하단의 작은 `관리` 링크에서 처리하며, 기능 버튼 진입을 위한 비밀번호 입력 화면에는 암호 변경 링크를 노출하지 않습니다.
메인 버튼은 기존 4개를 유지합니다. 암호 변경은 배너 우하단의 작은 `관리` 링크에서 처리하며, 이 링크는 Rhymix 사이트 관리자 로그인 상태에서만 표시합니다. 기능 버튼 진입을 위한 비밀번호 입력 화면에는 암호 변경 링크를 노출하지 않습니다.
+4
View File
@@ -66,6 +66,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
custom_json(['authenticated' => custom_has_auth_cookie()]);
}
if (isset($_GET['adminSession'])) {
custom_json(['admin' => custom_is_site_admin()]);
}
if (isset($_GET['failMessages'])) {
custom_json([
'failMessages' => [
+14 -1
View File
@@ -30,7 +30,7 @@ const iconItems = [
}
];
function renderIcons() {
async function renderIcons() {
shortcut.className = 'find-container';
shortcut.innerHTML = '';
@@ -53,6 +53,10 @@ function renderIcons() {
shortcut.appendChild(div);
});
if (!await hasAdminSession()) {
return;
}
const manage = document.createElement('button');
manage.type = 'button';
manage.className = 'launcher-manage';
@@ -61,6 +65,15 @@ function renderIcons() {
shortcut.appendChild(manage);
}
async function hasAdminSession() {
try {
const session = await fetch(`${apiUrl}?adminSession=1`, { credentials: 'same-origin' }).then(res => res.json());
return !!session.admin;
} catch (_) {
return false;
}
}
async function requireAccess(nextAction) {
try {
const session = await fetch(`${apiUrl}?session=1`, { credentials: 'same-origin' }).then(res => res.json());