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
@@ -0,0 +1,43 @@
"""Crée (ou met à jour le mot de passe d') un compte auteur : accès à l'éditeur de niveaux, rien d'autre."""
from __future__ import annotations
from getpass import getpass
from typing import Any
from django.contrib.auth.models import User
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand, CommandError, CommandParser
class Command(BaseCommand):
help = "Crée un compte auteur (is_staff, sans droits d'administration). Le mot de passe est demandé au clavier."
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument("username")
parser.add_argument("--reset", action="store_true", help="Change le mot de passe d'un compte existant")
def handle(self, *args: Any, **options: Any) -> None:
username: str = options["username"].strip().lower()
existing = User.objects.filter(username=username).first()
if existing and not options["reset"]:
raise CommandError(f"{username} existe déjà (utilise --reset pour changer son mot de passe).")
if not existing and options["reset"]:
raise CommandError(f"{username} n'existe pas.")
password = getpass("Mot de passe : ")
if password != getpass("Confirmation : "):
raise CommandError("Les mots de passe ne correspondent pas.")
try:
validate_password(password)
except ValidationError as error:
raise CommandError(" ".join(error.messages)) from error
user = existing or User(username=username)
user.is_staff = True
user.is_superuser = False
user.is_active = True
user.set_password(password)
user.save()
self.stdout.write(self.style.SUCCESS(f"Compte auteur {username} {'mis à jour' if existing else 'créé'}."))