feat(beta): inscription libre avec acces immediat, conservation IP 13 mois LCEN et gestion testeurs

Cette révision appartient à :
Théo Gastinel a révisé 2026-10-30 19:13:25 +01:00
1 Parent 6dc0f6c296
révision 66e2988a14
7 fichiers modifiés
+481 -195

Aucun fichier ne correspond à votre recherche

+41 -2
Voir le fichier
@@ -15,6 +15,8 @@ from pathlib import Path
ICI = Path(__file__).resolve().parent
ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789" # sans I, L, O, 0, 1
RETENTION_IP_S = 396 * 86400 # 13 mois (~396 jours, obligation légale LCEN / décret 2021-1362)
def dossier_data():
@@ -54,7 +56,7 @@ CREATE TABLE IF NOT EXISTS codes(
created_at REAL NOT NULL, expires_at REAL, revoked_at REAL,
last_used_at REAL, uses INTEGER NOT NULL DEFAULT 0, max_sessions INTEGER NOT NULL DEFAULT 3);
CREATE TABLE IF NOT EXISTS sessions(
token_hash TEXT PRIMARY KEY, code_id INTEGER NOT NULL, created_at REAL NOT NULL,
token_hash TEXT PRIMARY KEY, code_id INTEGER, tester_id INTEGER, ip TEXT, created_at REAL NOT NULL,
expires_at REAL NOT NULL, last_seen REAL);
CREATE TABLE IF NOT EXISTS attempts(
id INTEGER PRIMARY KEY, ts REAL NOT NULL, ip_hash TEXT NOT NULL, ok INTEGER NOT NULL, reason TEXT);
@@ -67,7 +69,8 @@ CREATE TABLE IF NOT EXISTS testers(
id INTEGER PRIMARY KEY, ts REAL NOT NULL, nom TEXT, prenom TEXT, email TEXT, tel TEXT,
naissance TEXT, mineur INTEGER, parent_nom TEXT, parent_email TEXT,
accord_participation INTEGER, rgpd INTEGER, confidentialite INTEGER, age_ok INTEGER,
suivi_reseaux INTEGER, source TEXT);
suivi_reseaux INTEGER, source TEXT,
ip TEXT DEFAULT '', expire_ip_at REAL DEFAULT 0, actif INTEGER NOT NULL DEFAULT 1, last_seen REAL);
CREATE TABLE IF NOT EXISTS demo_profiles(
id INTEGER PRIMARY KEY, created_at REAL, first TEXT, last_initial TEXT, city TEXT, dept TEXT,
region TEXT, seed TEXT, bio TEXT);
@@ -93,11 +96,47 @@ def connect(path=None, check_same_thread=True):
return c
def _migrer(c):
# Migration douce pour les bases existantes
try:
cols_t = [r[1] for r in c.execute("PRAGMA table_info(testers)").fetchall()]
if "ip" not in cols_t:
c.execute("ALTER TABLE testers ADD COLUMN ip TEXT DEFAULT ''")
if "expire_ip_at" not in cols_t:
c.execute("ALTER TABLE testers ADD COLUMN expire_ip_at REAL DEFAULT 0")
if "actif" not in cols_t:
c.execute("ALTER TABLE testers ADD COLUMN actif INTEGER DEFAULT 1")
if "last_seen" not in cols_t:
c.execute("ALTER TABLE testers ADD COLUMN last_seen REAL")
cols_s = [r[1] for r in c.execute("PRAGMA table_info(sessions)").fetchall()]
if "tester_id" not in cols_s:
c.execute("ALTER TABLE sessions ADD COLUMN tester_id INTEGER")
if "ip" not in cols_s:
c.execute("ALTER TABLE sessions ADD COLUMN ip TEXT")
c.commit()
except Exception:
pass
def purger_anciennes_ip(c):
"""Anonymise les adresses IP échues (au-delà de 13 mois de rétention légale LCEN)."""
now = time.time()
try:
c.execute("UPDATE testers SET ip='[PURGE_13_MOIS]' WHERE expire_ip_at > 0 AND expire_ip_at <= ?", (now,))
c.execute("UPDATE sessions SET ip='[PURGE_13_MOIS]' WHERE expires_at <= ?", (now - RETENTION_IP_S,))
c.commit()
except Exception:
pass
def _ouvrir(path, check_same_thread):
c = sqlite3.connect(str(path or dossier_prive() / "beta.sqlite"), timeout=10, check_same_thread=check_same_thread)
c.row_factory = sqlite3.Row
c.execute("PRAGMA journal_mode=WAL")
c.executescript(SCHEMA)
_migrer(c)
purger_anciennes_ip(c)
return c