66 lines
2.8 KiB
HTML
66 lines
2.8 KiB
HTML
{% 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 %}
|