Base Website
Basic Website, mit Login, Homepage, Usericon, Profilsettings, adminsettings. (KI)
This commit is contained in:
1 parent
99cea87151
commit
c4cef10909
8 files changed
+424
-14
No files matched your search
@@ -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 %}
|
||||
Reference in new issue
Block a user