Base Website

Basic Website, mit Login, Homepage, Usericon, Profilsettings, adminsettings.
(KI)
This commit is contained in:
Rudi committed 2026-09-23 23:07:35 +02:00
1 parent 99cea87151
commit c4cef10909
8 files changed
+424 -14

No files matched your search

+154
View File
@@ -0,0 +1,154 @@
{% extends "base.html" %}
{% block title %}Admin – Tandur{% endblock %}
{% block content %}
{% include "navbar.html" %}
<main class="mx-auto max-w-5xl px-4 py-10" x-data="adminPanel()" x-init="load()">
<div class="mb-8 flex items-center justify-between">
<h1 class="font-display text-2xl font-semibold">Benutzer</h1>
<button @click="openCreate()" class="rounded bg-marker px-4 py-2 text-sm font-medium text-board hover:brightness-95">
Benutzer anlegen
</button>
</div>
<p x-show="error" x-text="error" class="mb-4 text-sm text-brick" style="display:none"></p>
<div class="overflow-hidden rounded border border-panel">
<table class="w-full text-left text-sm">
<thead class="bg-panel text-muted">
<tr>
<th class="px-4 py-2 font-medium">E-Mail</th>
<th class="px-4 py-2 font-medium">Rolle</th>
<th class="px-4 py-2 font-medium"></th>
</tr>
</thead>
<tbody>
<template x-for="u in users" :key="u.id">
<tr class="border-t border-panel">
<td class="px-4 py-2" x-text="u.email"></td>
<td class="px-4 py-2" x-text="u.role"></td>
<td class="space-x-3 px-4 py-2 text-right">
<button @click="openEdit(u)" class="text-marker hover:underline">Bearbeiten</button>
<button @click="remove(u)" class="text-brick hover:underline">Löschen</button>
</td>
</tr>
</template>
<tr x-show="!loading && users.length === 0">
<td colspan="3" class="px-4 py-6 text-center text-muted">Keine Benutzer vorhanden.</td>
</tr>
</tbody>
</table>
</div>
<!-- Modal: Anlegen / Bearbeiten -->
<div x-show="modalOpen" style="display:none" class="fixed inset-0 z-10 flex items-center justify-center bg-black/50 px-4">
<div class="w-full max-w-sm rounded border border-panel bg-panel p-6">
<h2 class="mb-4 font-display text-lg font-semibold" x-text="editing ? 'Benutzer bearbeiten' : 'Benutzer anlegen'"></h2>
<form @submit.prevent="save" class="space-y-4">
<div>
<label class="mb-1 block text-sm text-muted">E-Mail</label>
<input type="username" x-model="form.email" required
class="w-full rounded border border-board bg-board px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
</div>
<div>
<label class="mb-1 block text-sm text-muted" x-text="editing ? 'Neues Passwort (optional)' : 'Passwort'"></label>
<input type="password" x-model="form.password" :required="!editing"
class="w-full rounded border border-board bg-board px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
</div>
<div>
<label class="mb-1 block text-sm text-muted">Rolle</label>
<select x-model="form.role" class="w-full rounded border border-board bg-board px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
<option value="user">user</option>
<option value="admin">admin</option>
</select>
</div>
<p x-show="formError" x-text="formError" class="text-sm text-brick" style="display:none"></p>
<div class="flex justify-end gap-3 pt-2">
<button type="button" @click="modalOpen = false" class="rounded px-4 py-2 text-sm text-muted hover:text-chalk">Abbrechen</button>
<button type="submit" class="rounded bg-marker px-4 py-2 text-sm font-medium text-board hover:brightness-95">Speichern</button>
</div>
</form>
</div>
</div>
</main>
<script>
function adminPanel() {
return {
users: [],
loading: true,
error: '',
modalOpen: false,
editing: null,
form: { email: '', password: '', role: 'user' },
formError: '',
async load() {
this.loading = true;
this.error = '';
const res = await fetch('/api/users/', { credentials: 'same-origin' });
if (res.status === 401) {
window.location.href = '/login?next=/admin';
return;
}
if (res.status === 404) {
// Backend meldet "keine User" als 404 statt leerer Liste
this.users = [];
} else if (!res.ok) {
this.error = 'Benutzer konnten nicht geladen werden.';
} else {
this.users = await res.json();
}
this.loading = false;
},
openCreate() {
this.editing = null;
this.form = { email: '', password: '', role: 'user' };
this.formError = '';
this.modalOpen = true;
},
openEdit(u) {
this.editing = u;
this.form = { email: u.email, password: '', role: u.role };
this.formError = '';
this.modalOpen = true;
},
async save() {
this.formError = '';
const payload = { email: this.form.email, role: this.form.role };
if (this.form.password) payload.password = this.form.password;
const url = this.editing ? `/api/users/${this.editing.id}` : '/api/users/';
const method = this.editing ? 'PATCH' : 'POST';
const res = await fetch(url, {
method,
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify(payload)
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
this.formError = data.detail || 'Speichern fehlgeschlagen.';
return;
}
this.modalOpen = false;
await this.load();
},
async remove(u) {
if (!confirm(`Benutzer ${u.email} wirklich löschen?`)) return;
const res = await fetch(`/api/users/${u.id}`, { method: 'DELETE', credentials: 'same-origin' });
if (res.ok) await this.load();
}
}
}
</script>
{% endblock %}
+29 -5
View File
@@ -2,15 +2,39 @@
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Shoppingliste</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Tandur{% endblock %}</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&display=swap" rel="stylesheet">
<!-- Tailwind via CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
board: '#1F2B22', /* Hintergrund: dunkles Tafel-Grün */
panel: '#26332A', /* Flächen/Karten */
chalk: '#F2EFE6', /* Text */
muted: '#A9B3A6', /* Text, gedämpft */
marker: '#E8B93A', /* Akzent / primäre Aktion */
brick: '#C1553D', /* Warnung / destruktive Aktion */
},
fontFamily: {
display: ['"Space Grotesk"', 'sans-serif'],
},
}
}
}
</script>
<!-- Alpine.js via CDN -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
{% block head %}{% endblock %}
</head>
<body class="bg-gray-100 p-8">
<div class="max-w-2xl mx-auto bg-white p-6 rounded-lg shadow-md">
{% block content %}{% endblock %}
</div>
<body class="min-h-screen bg-board text-chalk antialiased">
{% block content %}{% endblock %}
</body>
</html>
+12 -5
View File
@@ -1,8 +1,15 @@
{% extends "base.html" %}
{% block title %}Tandur{% endblock %}
{% block content %}
<div x-data="{ title: 'Meine Shoppingliste' }">
<h1 class="text-2xl font-bold mb-4" x-text="title"></h1>
<p>Das Grundgerüst steht!</p>
</div>
{% include "navbar.html" %}
<main class="mx-auto max-w-5xl px-4 py-10">
<h1 class="font-display text-2xl font-semibold mb-2">Einkaufsliste</h1>
<p class="mb-8 text-muted">Angemeldet als {{ user.email }}</p>
<button type="button" disabled title="Noch nicht implementiert"
class="cursor-not-allowed rounded bg-marker px-4 py-2 font-medium text-board opacity-60">
Daten laden
</button>
</main>
{% endblock %}
+65
View File
@@ -0,0 +1,65 @@
{% extends "base.html" %}
{% block title %}Anmelden – Tandur{% endblock %}
{% block content %}
<div class="flex min-h-screen items-center justify-center px-4">
<div class="w-full max-w-sm">
<h1 class="font-display text-2xl font-semibold mb-1">Tandur</h1>
<p class="mb-8 text-sm text-muted">Melde dich an, um deine Einkaufsliste zu sehen.</p>
<form x-data="loginForm()" @submit.prevent="submit" class="space-y-4" novalidate>
<div>
<label for="email" class="mb-1 block text-sm text-muted">E-Mail</label>
<input id="email" type="email" x-model="email" required autocomplete="username"
class="w-full rounded border border-panel bg-panel px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
</div>
<div>
<label for="password" class="mb-1 block text-sm text-muted">Passwort</label>
<input id="password" type="password" x-model="password" required autocomplete="current-password"
class="w-full rounded border border-panel bg-panel px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
</div>
<p x-show="error" x-text="error" class="text-sm text-brick" style="display:none"></p>
<button type="submit" :disabled="loading"
class="w-full rounded bg-marker py-2 font-medium text-board hover:brightness-95 disabled:opacity-60">
<span x-text="loading ? 'Anmelden …' : 'Anmelden'"></span>
</button>
</form>
</div>
</div>
<script>
function loginForm() {
return {
email: '',
password: '',
error: '',
loading: false,
async submit() {
this.error = '';
this.loading = true;
try {
const res = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify({ username: this.email, password: this.password })
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
this.error = data.detail || 'Anmeldung fehlgeschlagen.';
return;
}
// "next" kommt aus der URL, die main.py beim Redirect zu /login gesetzt hat
const params = new URLSearchParams(window.location.search);
window.location.href = params.get('next') || '/';
} catch (e) {
this.error = 'Server nicht erreichbar.';
} finally {
this.loading = false;
}
}
}
}
</script>
{% endblock %}
+26
View File
@@ -0,0 +1,26 @@
<header class="border-b border-panel">
<div class="mx-auto flex max-w-5xl items-center justify-between px-4 py-3">
<a href="/" class="font-display text-lg font-semibold tracking-tight">Tandur</a>
<div x-data="{ open: false }" class="relative">
<button @click="open = !open" @click.outside="open = false"
class="flex h-9 w-9 items-center justify-center rounded border border-panel transition-colors hover:border-marker"
aria-label="Menü öffnen" aria-haspopup="true" :aria-expanded="open">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
<circle cx="12" cy="8" r="3.2"/>
<path d="M4.5 20c1.4-3.6 4.2-5.4 7.5-5.4s6.1 1.8 7.5 5.4"/>
</svg>
</button>
<div x-show="open" x-transition.origin.top.right style="display: none;"
class="absolute right-0 mt-2 w-48 rounded border border-panel bg-panel py-1 shadow-lg shadow-black/30 z-10">
<a href="/profile" class="block px-4 py-2 text-sm hover:bg-board">Profil</a>
{% if user.role == "admin" %}
<a href="/admin" class="block px-4 py-2 text-sm hover:bg-board">Admin-Einstellungen</a>
{% endif %}
<div class="my-1 border-t border-board"></div>
<a href="/logout" class="block px-4 py-2 text-sm text-brick hover:bg-board">Abmelden</a>
</div>
</div>
</div>
</header>
+73
View File
@@ -0,0 +1,73 @@
{% extends "base.html" %}
{% block title %}Profil – Tandur{% endblock %}
{% block content %}
{% include "navbar.html" %}
<main class="mx-auto max-w-md px-4 py-10">
<h1 class="font-display text-2xl font-semibold mb-8">Profil</h1>
<form x-data="profileForm()" x-init="init($el.dataset)"
data-user-id="{{ user.id }}" data-email="{{ user.email }}"
@submit.prevent="save" class="space-y-4">
<div>
<label class="mb-1 block text-sm text-muted">E-Mail</label>
<input type="email" x-model="email" required
class="w-full rounded border border-panel bg-panel px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
</div>
<div>
<label class="mb-1 block text-sm text-muted">Neues Passwort (optional)</label>
<input type="password" x-model="password" autocomplete="new-password"
class="w-full rounded border border-panel bg-panel px-3 py-2 text-chalk focus:outline-none focus:ring-2 focus:ring-marker">
</div>
<div class="text-sm text-muted">Rolle: <span class="text-chalk">{{ user.role }}</span></div>
<p x-show="message" x-text="message" :class="success ? 'text-marker' : 'text-brick'" class="text-sm" style="display:none"></p>
<button type="submit" class="rounded bg-marker px-4 py-2 font-medium text-board hover:brightness-95">
Speichern
</button>
</form>
</main>
<script>
function profileForm() {
return {
userId: null,
email: '',
password: '',
message: '',
success: false,
init(dataset) {
this.userId = dataset.userId;
this.email = dataset.email;
},
async save() {
this.message = '';
const payload = { email: this.email };
if (this.password) payload.password = this.password;
const res = await fetch(`/api/users/${this.userId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify(payload)
});
if (res.status === 401) {
window.location.href = '/login?next=/profile';
return;
}
if (!res.ok) {
const data = await res.json().catch(() => ({}));
this.message = data.detail || 'Speichern fehlgeschlagen.';
this.success = false;
return;
}
this.password = '';
this.message = 'Gespeichert.';
this.success = true;
}
}
}
</script>
{% endblock %}