feat(ui): platform control panel and styled auth screens

Add the `controlpanel` app: a platform-wide (not club-scoped) admin panel for
creating clubs, archiving/restoring them, managing club admins, and per-club
statistics (members, teams & staff, events, shop). Statistics are annotated in
one query so the club list cannot fan out into N+1, and are returned as stat
*groups* so growing the domain means adding one entry.

Two access rules, both enforced by PlatformStaffRequiredMixin:
- staff only (is_staff/is_superuser); anonymous are sent to login, signed-in
  non-staff get a 403. Staff already need a second factor, so the panel is
  2FA-protected for free.
- base domain only: the panel manages *all* clubs, so it 404s if the tenant
  middleware resolved a club from the subdomain.

Granting admin to an unknown email creates the account (unusable password —
they set one via password reset) and the Member behind it, since a ClubRole
hangs off a Member. A member who already holds a role is promoted in place,
because there is only one role per member per club.

UI is Tailwind + daisyUI. allauth ships an element system, so overriding
allauth/layouts/base.html plus ~13 element partials restyles *every* auth and
2FA screen at once — login, signup, password reset, the 2FA challenge, TOTP
enrolment, passkeys and recovery codes — rather than templating 20+ pages.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-13 15:29:24 +02:00
parent 848a8578de
commit 6f66df3ba4
41 changed files with 1130 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
{% load allauth %}
<div class="alert {% if attrs.level == 'error' %}alert-error{% elif attrs.level == 'warning' %}alert-warning{% elif attrs.level == 'success' %}alert-success{% else %}alert-info{% endif %} my-2">
<span>{% slot message %}{% endslot %}</span>
</div>

View File

@@ -0,0 +1 @@
{% load allauth %}<span class="badge badge-neutral">{% slot %}{% endslot %}</span>

View File

@@ -0,0 +1,13 @@
{% load allauth %}
{% comment %} djlint:off {% endcomment %}
<{% if attrs.href %}a href="{{ attrs.href }}"{% else %}button{% endif %}
class="btn {% if attrs.tags and 'danger' in attrs.tags %}btn-error{% elif attrs.tags and 'secondary' in attrs.tags %}btn-ghost{% elif attrs.tags and 'link' in attrs.tags %}btn-link{% else %}btn-primary{% endif %}"
{% if attrs.form %}form="{{ attrs.form }}"{% endif %}
{% if attrs.id %}id="{{ attrs.id }}"{% endif %}
{% if attrs.name %}name="{{ attrs.name }}"{% endif %}
{% if attrs.value %}value="{{ attrs.value }}"{% endif %}
{% if attrs.type %}type="{{ attrs.type }}"{% endif %}
>
{% slot %}
{% endslot %}
</{% if attrs.href %}a{% else %}button{% endif %}>

View File

@@ -0,0 +1,4 @@
{% load allauth %}
<div class="flex flex-wrap gap-2">
{% slot %}{% endslot %}
</div>

View File

@@ -0,0 +1,5 @@
{% load allauth %}
<details class="collapse-arrow collapse border border-base-300 bg-base-100 my-2" {% if attrs.open %}open{% endif %}>
<summary class="collapse-title font-medium">{% slot summary %}{% endslot %}</summary>
<div class="collapse-content">{% slot body %}{% endslot %}</div>
</details>

View File

@@ -0,0 +1,24 @@
{% load ui %}
{% for field in attrs.form.hidden_fields %}{{ field }}{% endfor %}
{% for error in attrs.form.non_field_errors %}
<div class="alert alert-error my-2">
<span>{{ error }}</span>
</div>
{% endfor %}
{% for field in attrs.form.visible_fields %}
<div class="form-control my-3 w-full">
{% if field.field.widget.input_type == "checkbox" %}
<label class="label cursor-pointer justify-start gap-3" for="{{ field.id_for_label }}">
{{ field|daisy }}
<span class="label-text">{{ field.label }}</span>
</label>
{% else %}
<label class="label" for="{{ field.id_for_label }}">
<span class="label-text">{{ field.label }}</span>
</label>
{{ field|daisy }}
{% endif %}
{% if field.help_text %}<span class="label-text-alt mt-1 text-base-content/70">{{ field.help_text }}</span>{% endif %}
{% for error in field.errors %}<span class="label-text-alt mt-1 text-error">{{ error }}</span>{% endfor %}
</div>
{% endfor %}

View File

@@ -0,0 +1,9 @@
{% load allauth %}
<form method="{{ attrs.method }}"
{% if attrs.action %}action="{{ attrs.action }}"{% endif %}
class="space-y-2">
{% slot body %}{% endslot %}
<div class="card-actions justify-end pt-3">
{% slot actions %}{% endslot %}
</div>
</form>

View File

@@ -0,0 +1 @@
{% comment %} djlint:off {% endcomment %}{% load allauth %}<h1 class="card-title text-2xl">{% slot %}{% endslot %}</h1>

View File

@@ -0,0 +1 @@
{% comment %} djlint:off {% endcomment %}{% load allauth %}<h2 class="text-xl font-semibold">{% slot %}{% endslot %}</h2>

View File

@@ -0,0 +1 @@
{% comment %} djlint:off {% endcomment %}{% load allauth %}<div class="divider"></div>

View File

@@ -0,0 +1 @@
{% comment %} djlint:off {% endcomment %}{% load allauth %}<p class="text-base-content/80">{% slot %}{% endslot %}</p>

View File

@@ -0,0 +1,8 @@
{% load allauth %}
<div class="card border border-base-300 bg-base-100 my-4">
<div class="card-body gap-2">
{% if slots.title %}<h2 class="card-title text-lg">{% slot title %}{% endslot %}</h2>{% endif %}
<div>{% slot body %}{% endslot %}</div>
{% if slots.actions %}<div class="card-actions justify-end">{% slot actions %}{% endslot %}</div>{% endif %}
</div>
</div>

View File

@@ -0,0 +1,6 @@
{% load allauth %}
<div class="overflow-x-auto">
<table class="table">
{% slot %}{% endslot %}
</table>
</div>

View File

@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block title %}
{% block head_title %}{% endblock head_title %} · ClubManager
{% endblock title %}
{% block main %}
<div class="flex justify-center">
<div class="card w-full max-w-xl bg-base-100 shadow">
<div class="card-body prose max-w-none">
{% block content %}{% endblock content %}
</div>
</div>
</div>
{% endblock main %}

86
templates/base.html Normal file
View File

@@ -0,0 +1,86 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
{% block title %}ClubManager{% endblock title %}
</title>
{# Apply the stored theme before first paint, otherwise the page flashes
the wrong colours. With no stored preference we set nothing, so
daisyUI's `dark --prefersdark` follows the OS. #}
<script>
(() => {
const stored = localStorage.getItem("theme");
if (stored) document.documentElement.setAttribute("data-theme", stored);
})();
</script>
<link rel="stylesheet" href="{% static 'css/app.css' %}">
{% block extra_head %}{% endblock extra_head %}
</head>
<body class="min-h-screen bg-base-200">
<div class="navbar bg-base-100 shadow-sm">
<div class="flex-1">
<a class="btn btn-ghost text-xl" href="/">ClubManager</a>
{% if user.is_authenticated and user.is_staff %}
<a class="btn btn-ghost btn-sm" href="{% url 'controlpanel:dashboard' %}">Control panel</a>
{% endif %}
</div>
<div class="flex-none gap-2">
<button class="btn btn-ghost btn-circle"
aria-label="Toggle theme"
data-theme-toggle
type="button">
<svg class="h-5 w-5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /></svg>
</button>
{% if user.is_authenticated %}
<div class="dropdown dropdown-end">
<div tabindex="0" role="button" class="btn btn-ghost btn-sm">{{ user }}</div>
<ul tabindex="0"
class="menu dropdown-content z-10 mt-2 w-56 rounded-box bg-base-100 p-2 shadow">
<li>
<a href="{% url 'mfa_index' %}">Two-factor authentication</a>
</li>
<li>
<a href="{% url 'account_change_password' %}">Change password</a>
</li>
<li>
<a href="{% url 'account_logout' %}">Sign out</a>
</li>
</ul>
</div>
{% else %}
<a class="btn btn-primary btn-sm" href="{% url 'account_login' %}">Sign in</a>
{% endif %}
</div>
</div>
{% if messages %}
<div class="mx-auto mt-4 w-full max-w-5xl space-y-2 px-4">
{% for message in messages %}
<div class="alert {% if message.tags == 'error' %}alert-error{% elif message.tags == 'warning' %}alert-warning{% elif message.tags == 'success' %}alert-success{% else %}alert-info{% endif %}">
<span>{{ message }}</span>
</div>
{% endfor %}
</div>
{% endif %}
<main class="mx-auto w-full max-w-5xl p-4">
{% block main %}{% endblock main %}
</main>
<script>
// No stored preference means "follow the OS", so read the effective theme
// from the OS when nothing is set yet.
document.querySelectorAll("[data-theme-toggle]").forEach((button) => {
button.addEventListener("click", () => {
const current =
document.documentElement.getAttribute("data-theme") ||
(window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
const next = current === "dark" ? "light" : "dark";
document.documentElement.setAttribute("data-theme", next);
localStorage.setItem("theme", next);
});
});
</script>
</body>
</html>