Add invite-code registration and admin user management

Open registration let anyone with the URL create an account. Two
changes address that:

- REGISTRATION_CODE (.env, optional): when set, registration requires
  entering it correctly. Empty/unset keeps registration open, so
  existing installs are unaffected until configured.
- is_admin flag on User: the first account ever created on an install
  becomes admin automatically (existing installs get their oldest
  account promoted via the startup migration, so nobody is locked
  out of user management after upgrading).

Admins get a new "Benutzerverwaltung" panel in Einstellungen listing
every account (email, link/prompt counts, join date) with a delete
button per account — deleting cascades to that user's links and
prompts via the existing relationship cascade. Deleting your own
account through this page is blocked (redirects with an error) to
avoid accidental admin lockout. Non-admins get a 403 on the
/settings/users routes.

Also fixes several pre-existing German pluralization bugs found while
writing the new counts ("2 Linke" -> "2 Links", "Kontoen"/"Konton" ->
"Konten") — irregular plurals need a full word swap, not a suffix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Erik Thiele
2026-07-31 11:16:01 +02:00
parent 517652708a
commit 604c4ea9c2
8 changed files with 181 additions and 9 deletions

View File

@@ -8,18 +8,29 @@
<main class="main">
<h1 style="margin-top:0;">Einstellungen</h1>
<p class="muted" style="margin-top:-8px;">
Angemeldet als {{ user.email }} &middot; {{ link_count }} Link{{ '' if link_count == 1 else 'e' }}
Angemeldet als {{ user.email }} &middot; {{ link_count }} Link{{ '' if link_count == 1 else 's' }}
</p>
{% if imported is not none %}
<div class="panel" style="border-color:#16a34a;">
{{ icons.sparkles(size=15) }} {{ imported }} Link{{ '' if imported == '1' else 'e' }} erfolgreich importiert.
{{ icons.sparkles(size=15) }} {{ imported }} Link{{ '' if imported == '1' else 's' }} erfolgreich importiert.
</div>
{% endif %}
{% if import_error %}
<div class="error">{{ import_error }}</div>
{% endif %}
{% if user.is_admin %}
<div class="panel">
<h2 style="margin-top:0; font-size:1.05rem;">Benutzerverwaltung</h2>
<p class="muted">
{{ user_count }} {{ 'registriertes Konto' if user_count == 1 else 'registrierte Konten' }}.
Konten ansehen oder entfernen.
</p>
<a href="/settings/users"><button type="button">{{ icons.user(size=14) }} Benutzer verwalten</button></a>
</div>
{% endif %}
<div class="panel">
<h2 style="margin-top:0; font-size:1.05rem;">CSV-Export</h2>
<p class="muted">