A5: sign up, sign in, sign out, profile and the base layout (WEB-02, WEB-06, WEB-11, WEB-50..54)

Registration (case-insensitive unique names, 8-256 char passwords, no email),
sign-in with a generic error and a fresh session, internal-only ?next=,
POST-only sign-out, password change that closes the other sessions. The
failed-login backoff, the registration quota and the password-change guard
live in the database so every web process shares them; the client IP is the
last X-Forwarded-For hop. One responsive stylesheet with light/dark theme,
labelled fields, alerts and no inline scripts or styles; Italian error pages
and a readable CSRF failure. Mutation checks: open redirects, uncounted
failures and a missing CSRF middleware are all caught.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 14:07:45 +01:00
1 parent 1d4b53d778
commit efb3e2e702
28 files changed
+1232 -22

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
/* One stylesheet for the whole site (ADR-54). Mobile first, no inline styles or scripts anywhere, so the
Content-Security-Policy can be tightened for these pages (Caddyfile). */
:root {
--bg: #f6f7f9; --surface: #ffffff; --text: #16202a; --muted: #5a6672; --line: #d9dee4;
--accent: #1b5fd6; --accent-text: #ffffff; --error: #b42318; --error-bg: #fdecea; --ok: #067647; --ok-bg: #e7f6ec;
--radius: 10px; --gap: 1rem;
color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #10161c; --surface: #19222b; --text: #e8edf2; --muted: #9aa7b3; --line: #2b3742;
--accent: #6ea0ff; --accent-text: #0b1220; --error: #ff8f85; --error-bg: #3a1d1b; --ok: #6ddba0; --ok-bg: #12301f;
}
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.55;
font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 1.2rem 0 .8rem; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; }
a { color: var(--accent); }
.wrap { width: 100%; max-width: 60rem; margin-inline: auto; padding-inline: 1rem; }
main { padding-block: 1rem 3rem; min-height: 60vh; }
main:focus { outline: none; }
.skip-link { position: absolute; left: .5rem; top: -4rem; background: var(--accent); color: var(--accent-text);
padding: .6rem 1rem; border-radius: var(--radius); z-index: 10; }
.skip-link:focus { top: .5rem; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding-block: .6rem; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .9rem; }
.nav a { text-decoration: none; padding: .5rem .2rem; }
.nav a.button { padding: .5rem .9rem; }
.inline { display: inline; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin-block: 1rem; }
.narrow { max-width: 28rem; }
.field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .3rem; }
input[type=text], input[type=password] { width: 100%; min-height: 2.75rem; padding: .55rem .75rem; font: inherit; color: var(--text);
background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.has-error input { border-color: var(--error); }
.hint { color: var(--muted); font-size: .9rem; margin: .3rem 0 0; }
.error { color: var(--error); font-size: .95rem; margin: .3rem 0 0; }
.error.box { background: var(--error-bg); border-radius: 8px; padding: .6rem .8rem; margin: 0 0 1rem; }
.messages { margin-block: 1rem 0; }
.message { background: var(--ok-bg); color: var(--ok); border-radius: 8px; padding: .6rem .8rem; margin: 0 0 .5rem; }
.message.error { background: var(--error-bg); color: var(--error); }
.button, .link-button { font: inherit; cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.75rem; padding: .55rem 1.2rem; border: 0;
border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }
.button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.button.small { min-height: 2.25rem; padding: .3rem .9rem; }
.link-button { background: none; border: 0; color: var(--accent); padding: .5rem .2rem; text-decoration: underline; }
.aside { color: var(--muted); margin: 1rem 0 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; padding-block: 1rem; }
/* Keyboard users always see where they are (WEB-06). */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (min-width: 40rem) { h1 { font-size: 2rem; } .card { padding: 1.6rem; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
+6
View File
@@ -0,0 +1,6 @@
{% extends "web/base.html" %}
{% block title %}Gioca · PLM Lottery{% endblock %}
{% block content %}
<h1>Area giocatore</h1>
<p>Ciao {{ user.get_username }}. La schermata di gioco è in costruzione.</p>
{% endblock %}
+47
View File
@@ -0,0 +1,47 @@
{% load static %}<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
<title>{% block title %}PLM Lottery{% endblock %}</title>
<link rel="stylesheet" href="{% static 'web/site.css' %}">
</head>
<body>
<a class="skip-link" href="#contenuto">Vai al contenuto</a>
<header class="site-header">
<div class="wrap bar">
<a class="brand" href="{% url 'web:home' %}">PLM Lottery</a>
<nav class="nav" aria-label="Principale">
<a href="{% url 'web:home' %}">Home</a>
{% if user.is_authenticated %}
<a href="{% url 'web:app-home' %}">Gioca</a>
<a href="{% url 'accounts:profile' %}">Profilo</a>
<form class="inline" method="post" action="{% url 'accounts:logout' %}">
{% csrf_token %}
<button class="link-button" type="submit">Esci ({{ user.get_username }})</button>
</form>
{% else %}
<a href="{% url 'accounts:login' %}">Accedi</a>
<a class="button small" href="{% url 'accounts:register' %}">Registrati</a>
{% endif %}
</nav>
</div>
</header>
<main id="contenuto" class="wrap" tabindex="-1">
{% if messages %}
<div class="messages" role="status">
{% for message in messages %}<p class="message {{ message.tags }}">{{ message }}</p>{% endfor %}
</div>
{% endif %}
{% block content %}{% endblock %}
</main>
<footer class="site-footer">
<div class="wrap">
<p>Ambiente di prova su rete regtest: nessun denaro reale.</p>
</div>
</footer>
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
{% extends "web/base.html" %}
{% block title %}{{ title }} · PLM Lottery{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
<p>{{ message }}</p>
<p><a class="button" href="/">Torna alla home</a></p>
{% endblock %}
+5 -14
View File
@@ -1,14 +1,5 @@
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PLM Lottery</title>
</head>
<body>
<main>
<h1>PLM Lottery</h1>
<p>Il sito è in costruzione.</p>
</main>
</body>
</html>
{% extends "web/base.html" %}
{% block content %}
<h1>PLM Lottery</h1>
<p>Il sito è in costruzione.</p>
{% endblock %}
+1
View File
@@ -5,5 +5,6 @@ from . import views
app_name = "web"
urlpatterns = [
path("", views.home, name="home"),
path("app/", views.app_home, name="app-home"),
path("health/live", views.health_live, name="health-live"),
]
+33
View File
@@ -1,6 +1,8 @@
from django.contrib.auth.decorators import login_required
from django.db import connection
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.views.decorators.cache import never_cache
def home(request):
@@ -8,6 +10,13 @@ def home(request):
return render(request, "web/home.html")
@never_cache
@login_required
def app_home(request):
"""Placeholder of the player area (WEB-20): the play screen arrives with A7."""
return render(request, "web/app_home.html")
def health_live(request):
"""Liveness for the container healthcheck: the process answers and the database opens (ARC-73)."""
try:
@@ -16,3 +25,27 @@ def health_live(request):
except Exception:
return HttpResponse("database unavailable", status=503, content_type="text/plain")
return JsonResponse({"status": "ok"})
# Error pages in Italian, in the site's own layout, with a way out (WEB-06).
def csrf_failure(request, reason=""):
return render(request, "web/error.html", {
"title": "Sessione scaduta",
"message": "Il modulo non è più valido, probabilmente perché la pagina è rimasta aperta a lungo. "
"Ricarica la pagina e riprova.",
}, status=403)
def not_found(request, exception=None):
return render(request, "web/error.html", {
"title": "Pagina non trovata", "message": "L'indirizzo richiesto non esiste.",
}, status=404)
def server_error(request):
return render(request, "web/error.html", {
"title": "Qualcosa è andato storto",
"message": "Si è verificato un errore. Riprova fra qualche istante.",
}, status=500)