Add contact modal, success messages, form reset on open

This commit is contained in:
2026-05-14 06:42:09 +00:00
parent ba8f3cf753
commit b36b3f6325
3 changed files with 299 additions and 2 deletions
+52
View File
@@ -487,6 +487,58 @@ async def request_access(request: Request, db: Session = Depends(get_db)):
return {"ok": True}
@app.post("/api/contact")
async def contact_ruslan(request: Request):
import re as _re
try:
data = await request.json()
except Exception:
raise HTTPException(status_code=400, detail="Invalid JSON")
name = str(data.get("name", "")).strip()
email = str(data.get("email", "")).strip()
phone = str(data.get("phone", "")).strip()
text = str(data.get("text", "")).strip()
if not name or not email or not phone or not text:
raise HTTPException(status_code=422, detail="Заполните все обязательные поля")
if not _re.match(r"^[^\s@]+@[^\s@]+\.[^\s@]+$", email):
raise HTTPException(status_code=422, detail="Некорректный email")
if not _re.match(r"^[\+\d][\d\s\-\(\)]{6,18}$", phone):
raise HTTPException(status_code=422, detail="Некорректный номер телефона")
divider = "━━━━━━━━━━━━━━━━━━━━━━"
msg = (
f"🔔 *Сообщение через форму полигона*\n"
f"{divider}\n\n"
f"👤 *Имя:* {name}\n"
f"📧 *Email:* {email}\n"
f"📱 *Телефон:* {phone}\n\n"
f"💬 *Сообщение:*\n{text}"
)
if not TELEGRAM_BOT_TOKEN or not TELEGRAM_CHAT_ID:
log_event("telegram_not_configured")
return {"ok": True}
try:
payload = _json.dumps({
"chat_id": TELEGRAM_CHAT_ID,
"text": msg,
"parse_mode": "Markdown",
}).encode()
url = f"{TELEGRAM_API_URL}{TELEGRAM_BOT_TOKEN}/sendMessage"
req = _urllib_request.Request(url, data=payload, headers={"Content-Type": "application/json"})
with _urllib_request.urlopen(req, timeout=10) as resp:
resp.read()
except Exception as e:
log_event("telegram_send_error", error=str(e))
raise HTTPException(status_code=502, detail="Ошибка отправки")
return {"ok": True}
@app.post("/login")
def login(
request: Request,