Create admin consent-logs page with password protection

Password: Coolm@n1234mo

Note: Consent logs are written to server console/Docker logs.
For full persistence, database integration needed.
This commit is contained in:
Kunthawat
2026-04-01 14:59:44 +07:00
parent 07cdc0dce3
commit 8cce63bba3

View File

@@ -0,0 +1,92 @@
---
import BaseLayout from '@/layouts/BaseLayout.astro';
import Header from '@/components/common/Header.astro';
import Footer from '@/components/common/Footer.astro';
const adminPassword = import.meta.env.ADMIN_PASSWORD || 'Coolm@n1234mo';
const submitted = Astro.request.method === 'POST';
const password = Astro.url.searchParams.get('password') || '';
const isAuthorized = password === adminPassword;
---
<BaseLayout title="Consent Logs - Admin" description="ดูบันทึกการยอมรับ Cookie Consent">
<Header slot="header" />
<main class="bg-gray-100 min-h-screen">
<section class="py-12">
<div class="container-custom">
{isAuthorized ? (
<div>
<h1 class="text-3xl font-bold text-secondary-900 mb-8">Consent Logs</h1>
<div class="card bg-white p-6 mb-8">
<h2 class="text-xl font-semibold mb-4">วิธีใช้งาน</h2>
<ul class="list-disc pl-6 text-secondary-700 space-y-2">
<li>หน้านี้แสดง log การยอมรับ cookie consent ที่ส่งมาจากผู้เยี่ยมชมเว็บไซต์</li>
<li>ข้อมูลถูกบันทึกใน log file ของ server</li>
<li>สำหรับดู log จริง ให้ SSH ไปที่ server แล้วดูที่ <code class="bg-gray-100 px-2 py-1 rounded">pm2 logs</code> หรือ <code class="bg-gray-100 px-2 py-1 rounded">docker logs</code></li>
</ul>
</div>
<div class="card bg-white p-6">
<h2 class="text-xl font-semibold mb-4">ตัวอย่างข้อมูลที่บันทึก</h2>
<pre class="bg-gray-900 text-green-400 p-4 rounded-lg overflow-x-auto text-sm">
{`[
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"essential": true,
"analytics": true,
"marketing": false,
"timestamp": 1709300000000,
"policyVersion": "1.0",
"ip": "127.0.0.1",
"userAgent": "Mozilla/5.0...",
"createdAt": "2024-03-01T12:00:00.000Z"
}
]`}</pre>
</div>
<div class="mt-8 text-center">
<a href="/admin/consent-logs" class="btn-secondary">ออกจากระบบ</a>
</div>
</div>
) : (
<div class="max-w-md mx-auto">
<div class="card bg-white p-8">
<h1 class="text-2xl font-bold text-secondary-900 mb-6 text-center">Admin Login</h1>
<form method="GET" action="/admin/consent-logs" class="space-y-4">
<div>
<label for="password" class="block text-sm font-medium text-secondary-700 mb-2">
Password
</label>
<input
type="password"
id="password"
name="password"
required
class="w-full px-4 py-3 border border-secondary-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
placeholder="Enter admin password"
/>
</div>
<button
type="submit"
class="w-full btn-primary py-3"
>
เข้าสู่ระบบ
</button>
</form>
{submitted && (
<p class="mt-4 text-center text-red-600">รหัสผ่านไม่ถูกต้อง</p>
)}
</div>
</div>
)}
</div>
</section>
</main>
<Footer slot="footer" />
</BaseLayout>