feat: add admin pages for content management with edit, list and login functionality
This commit is contained in:
parent
5a6a4e77c2
commit
476bb096b0
@ -70,7 +70,7 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
||||
|
||||
const response = await fetch(getApiUrl(`content/${fileParam}`), {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + btoa('admin:password') // In production, use proper auth
|
||||
// Authorization header removed; browser will handle Basic Auth prompt
|
||||
}
|
||||
});
|
||||
|
||||
@ -111,8 +111,8 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
||||
const response = await fetch(url, {
|
||||
method: isNewFile ? 'POST' : 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Basic ' + btoa('admin:password') // In production, use proper auth
|
||||
'Content-Type': 'application/json'
|
||||
// Authorization header removed; browser will handle Basic Auth prompt
|
||||
},
|
||||
body: JSON.stringify({ filename, content })
|
||||
});
|
||||
|
||||
@ -31,7 +31,7 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + btoa('admin:password') // In production, use proper auth
|
||||
// Authorization header removed; browser will handle Basic Auth prompt
|
||||
}
|
||||
});
|
||||
|
||||
@ -74,7 +74,7 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + btoa('admin:password') // In production, use proper auth
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1,49 +1,6 @@
|
||||
---
|
||||
import SiteLayout from '../../components/SiteLayout.astro';
|
||||
|
||||
let error = '';
|
||||
if (Astro.request.method === 'POST') {
|
||||
try {
|
||||
const data = await Astro.request.formData();
|
||||
const username = data.get('username');
|
||||
const password = data.get('password');
|
||||
|
||||
// Simple client-side auth - real auth happens in the API
|
||||
if (username === 'admin' && password === 'password') {
|
||||
// Store authentication in a cookie or localStorage in a real app
|
||||
// src/pages/admin/login.astro
|
||||
// This page now just redirects to the main admin dashboard.
|
||||
// The API's Basic Auth will protect the actual data.
|
||||
return Astro.redirect('/admin');
|
||||
} else {
|
||||
error = 'Invalid username or password';
|
||||
}
|
||||
} catch (e) {
|
||||
error = 'An error occurred during login';
|
||||
}
|
||||
}
|
||||
---
|
||||
|
||||
<SiteLayout title="Admin Login">
|
||||
<div class="max-w-md mx-auto mt-10 p-6 bg-white rounded-lg shadow-md">
|
||||
<h1 class="text-2xl font-bold mb-6 text-center">Content Admin Login</h1>
|
||||
|
||||
{error && <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">{error}</div>}
|
||||
|
||||
<form method="POST" class="space-y-4">
|
||||
<div>
|
||||
<label for="username" class="block text-sm font-medium text-gray-700">Username</label>
|
||||
<input type="text" id="username" name="username" required
|
||||
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password" class="block text-sm font-medium text-gray-700">Password</label>
|
||||
<input type="password" id="password" name="password" required
|
||||
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
||||
</div>
|
||||
|
||||
<button type="submit"
|
||||
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
|
||||
Sign in
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</SiteLayout>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user