feat(register): поле Телефон/Telegram (в TG, не в БД) + тумблер регистрации + согласие ПДн

Самостоятельная регистрация по email+капча (как была), доработки: опц. поле контакта
(уходит в TG-алерт оператору, в БД не пишется), kill-switch регистрации в админке
(registration_enabled, при выкл /register и /verify-email → 403), обязательный чекбокс
согласия на обработку ПДн (без него → 400) + черновик static/privacy.html (баннер
«проверить у юриста»). Анти-бот переиспользован. +11 тестов.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
anor
2026-07-23 19:04:46 +10:00
co-authored by Claude Opus 4.8
parent 6a8529d432
commit 163d3ad2f8
7 changed files with 406 additions and 7 deletions
+5 -5
View File
@@ -111,7 +111,7 @@ def client_env(tmp_path, monkeypatch):
def test_register_disposable_400(client_env, monkeypatch):
db, auth, client, invite = client_env
r = client.post("/api/register", json={
"email": "bot@mailinator.com", "password": "secret1", "invite": invite})
"email": "bot@mailinator.com", "password": "secret1", "invite": invite, "consent": True})
assert r.status_code == 400
assert "почт" in r.json()["detail"].lower() or "email" in r.json()["detail"].lower()
assert db.get_user_by_email("bot@mailinator.com") is None
@@ -122,7 +122,7 @@ def test_register_normal_ok_without_captcha_keys(client_env, monkeypatch):
db, auth, client, invite = client_env
monkeypatch.setattr("email_service.send_verification_code", lambda e, c: True)
r = client.post("/api/register", json={
"email": "human@yandex.ru", "password": "secret1", "invite": invite})
"email": "human@yandex.ru", "password": "secret1", "invite": invite, "consent": True})
assert r.status_code == 200
assert db.get_user_by_email("human@yandex.ru") is not None
@@ -137,7 +137,7 @@ def test_register_sends_tg_notification(client_env, monkeypatch):
import alerts
monkeypatch.setattr(alerts, "send_tg", lambda text: sent.append(text) or True)
r = client.post("/api/register", json={
"email": "newbie@yandex.ru", "password": "secret1", "invite": invite})
"email": "newbie@yandex.ru", "password": "secret1", "invite": invite, "consent": True})
assert r.status_code == 200
assert len(sent) == 1 # ровно один алерт на регистрацию
assert "newbie@yandex.ru" in sent[0] # с email нового юзера
@@ -150,7 +150,7 @@ def test_register_normalizes_email_case_in_audit(client_env, monkeypatch):
db, auth, client, invite = client_env
monkeypatch.setattr("email_service.send_verification_code", lambda e, c: True)
r = client.post("/api/register", json={
"email": "Shelemetevay@MAIL.ru", "password": "secret1", "invite": invite})
"email": "Shelemetevay@MAIL.ru", "password": "secret1", "invite": invite, "consent": True})
assert r.status_code == 200
users = {row["username"] for row in db.get_audit_log(action="register") if row.get("username")}
assert "shelemetevay@mail.ru" in users
@@ -178,6 +178,6 @@ def test_failed_register_no_tg_notification(client_env, monkeypatch):
import alerts
monkeypatch.setattr(alerts, "send_tg", lambda text: sent.append(text) or True)
r = client.post("/api/register", json={
"email": "bot@mailinator.com", "password": "secret1", "invite": invite})
"email": "bot@mailinator.com", "password": "secret1", "invite": invite, "consent": True})
assert r.status_code == 400
assert sent == []