Webapp hardening + perf / CSP nonce-only / plugin-builder API guard + token autogen / cookie Secure / XSS fixes (QR, postMessage) / auth-me SWR dedup / SSR fetch cache / entry-capture redesign (gift/partner/referral) / payment webhooks (yoomoney sign, tribute trb_user_id) / email-only partners+referrals / INSTALL guide

This commit is contained in:
Vladless
2026-04-18 18:12:05 +00:00
parent cc2c9fbdba
commit 0b17346cb6
12 changed files with 122 additions and 15 deletions
+14
View File
@@ -119,6 +119,20 @@ async def register_by_email(
billing_user_id = await idb.ensure_billing_user_for_identity(session, identity)
if referrer_user is not None and not await get_referral_by_referred_id(session, billing_user_id):
await add_referral(session, billing_user_id, referrer_user.id)
if referrer_user.tg_id is not None:
try:
from database.web_notifications import notify_web
await notify_web(
session,
tg_id=int(referrer_user.tg_id),
type="referral_joined",
title="Ваш реферал присоединился",
message="Новый пользователь зарегистрировался по вашей реферальной ссылке.",
data={"referred_user_id": int(billing_user_id)},
)
except Exception:
pass
if smtp_configured():
try:
code = f"{secrets.randbelow(900000) + 100000}"
+21 -1
View File
@@ -109,8 +109,15 @@ async def _resolve_partner_user(session: AsyncSession, request: Request, identit
{"user_id": int(billing_user_id)},
)
).first()
if row is None or row[1] is None:
if row is None:
raise HTTPException(status_code=400, detail="Партнерский профиль недоступен")
if row[1] is None:
synthetic = -int(row[0])
await session.execute(
text("UPDATE users SET tg_id = :tg_id WHERE id = :user_id"),
{"tg_id": synthetic, "user_id": int(row[0])},
)
return int(row[0]), synthetic
return int(row[0]), int(row[1])
@@ -207,6 +214,19 @@ async def partner_apply(
),
{"partner_tg_id": int(referrer_tg_id), "joined_tg_id": int(joined_tg_id)},
)
try:
from database.web_notifications import notify_web
await notify_web(
session,
tg_id=int(referrer_tg_id),
type="partner_joined",
title="К вам присоединился партнёр",
message="Новый пользователь перешёл по вашей партнёрской ссылке.",
data={"joined_tg_id": int(joined_tg_id), "joined_user_id": int(joined_user_id)},
)
except Exception:
pass
await session.commit()
return PartnerApplyResponse(
ok=True,
+17
View File
@@ -93,6 +93,23 @@ async def apply_referral(
raise HTTPException(status_code=409, detail="Реферальная связь уже сохранена")
await add_referral(session, billing_uid, referrer_u.id)
referred_u = await resolve_user_optional(session, billing_uid)
if referrer_u.tg_id is not None:
try:
from database.web_notifications import notify_web
await notify_web(
session,
tg_id=int(referrer_u.tg_id),
type="referral_joined",
title="Ваш реферал присоединился",
message="Новый пользователь зарегистрировался по вашей реферальной ссылке.",
data={
"referred_tg_id": int(referred_u.tg_id) if referred_u and referred_u.tg_id else None,
"referred_user_id": int(billing_uid),
},
)
except Exception:
pass
return ReferralApplyResponse(
ok=True,
message="Приглашение применено",