2026-11-16 12:00:57 +01:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
|
|
|
from django.db import models
|
|
|
|
|
from django.db.models.functions import Lower
|
2026-11-16 14:07:45 +01:00
|
|
|
from django.utils import timezone
|
2026-11-16 12:00:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class User(AbstractUser):
|
|
|
|
|
"""Players and staff share one account model (ADR-54, ADR-56).
|
|
|
|
|
|
|
|
|
|
Staff is a role (`is_staff` plus explicit permissions), not a separate table.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
constraints = [
|
|
|
|
|
# ADR-38: one case-insensitive namespace. The name is stored as typed.
|
|
|
|
|
models.UniqueConstraint(Lower("username"), name="accounts_user_username_ci_unique"),
|
|
|
|
|
]
|
2026-11-16 14:07:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ThrottleEvent(models.Model):
|
|
|
|
|
"""One counted event of a throttle (failed login, registration, wrong current password).
|
|
|
|
|
|
|
|
|
|
In the database, not in memory: the web runs as several processes (ADR-55, ARC-72), and a throttle
|
|
|
|
|
kept in one process's memory is bypassed by whichever other process answers the next request.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
scope = models.CharField(max_length=16)
|
|
|
|
|
key = models.CharField(max_length=150)
|
|
|
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [models.Index(fields=["scope", "key", "created_at"])]
|