Files
Tandur/templates/login.html
T
Rudi c4cef10909 Base Website
Basic Website, mit Login, Homepage, Usericon, Profilsettings, adminsettings.
(KI)
2026-09-23 23:07:35 +02:00

66 lines
2.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{% 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 %}