Add Django author accounts for level editor access (login, nginx auth_request, brute-force lockout), MariaDB production settings

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
denis
2026-10-16 21:25:48 +02:00
parent 7eb508380a
commit 1e94840abd
26 changed files with 742 additions and 37 deletions
+36 -2
View File
@@ -1,17 +1,51 @@
"""Réglages communs. Le backend ne sert qu'à synchroniser la progression entre appareils."""
"""Réglages communs. Le backend sert à synchroniser la progression entre appareils et à protéger l'accès à
l'éditeur de niveaux (comptes auteurs). Il n'est jamais requis pour apprendre."""
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent.parent
INSTALLED_APPS = ["sync"]
INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.auth",
"django.contrib.sessions",
"sync",
"authors",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {"context_processors": ["django.template.context_processors.request"]},
}
]
# Session des auteurs (éditeur de niveaux) : cookie HttpOnly, 8 heures.
SESSION_COOKIE_NAME = "pyquest_author"
SESSION_COOKIE_AGE = 8 * 60 * 60
SESSION_COOKIE_SAMESITE = "Lax"
CSRF_COOKIE_NAME = "pyquest_csrf"
AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", "OPTIONS": {"min_length": 12}},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
# Vrai seulement derrière nginx, qui écrase X-Real-IP : sert à limiter les essais de connexion par adresse.
TRUST_REAL_IP_HEADER = False
ROOT_URLCONF = "pyquest_api.urls"
WSGI_APPLICATION = "pyquest_api.wsgi.application"
+11 -2
View File
@@ -16,14 +16,17 @@ DEBUG = False
SECRET_KEY = _required("PYQUEST_SECRET_KEY")
ALLOWED_HOSTS = _required("PYQUEST_ALLOWED_HOSTS").split(",")
# MariaDB (ou MySQL) : pilote `mysqlclient` (voir backend/requirements-prod.txt), jeu de caractères utf8mb4.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"ENGINE": "django.db.backends.mysql",
"NAME": _required("PYQUEST_DB_NAME"),
"USER": _required("PYQUEST_DB_USER"),
"PASSWORD": _required("PYQUEST_DB_PASSWORD"),
"HOST": os.environ.get("PYQUEST_DB_HOST", "127.0.0.1"),
"PORT": os.environ.get("PYQUEST_DB_PORT", "5432"),
"PORT": os.environ.get("PYQUEST_DB_PORT", "3306"),
"OPTIONS": {"charset": "utf8mb4"},
"CONN_MAX_AGE": 60,
}
}
@@ -32,3 +35,9 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 31536000
SECURE_CONTENT_TYPE_NOSNIFF = True
# Origine publique exacte (https://domaine) : requise pour les formulaires POST (connexion) derrière le proxy.
CSRF_TRUSTED_ORIGINS = [_required("PYQUEST_ORIGIN")]
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
TRUST_REAL_IP_HEADER = True # nginx écrase X-Real-IP (voir nginx/pyquest.conf.example)
+1
View File
@@ -2,4 +2,5 @@ from django.urls import include, path
urlpatterns = [
path("api/sync/", include("sync.urls")),
path("api/auth/", include("authors.urls")),
]