Add access request modal with Telegram notification

- Modal on login page: Name, Email, Phone with client-side validation
- POST /request-access → sends Telegram message via corporate proxy
- Includes IP + geo lookup (ip-api.com)
- Success screen after submission, Esc/click-outside closes modal

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 21:38:14 +03:00
parent 643ec4e0ca
commit a605c92ab3
2 changed files with 198 additions and 1 deletions
+58
View File
@@ -1427,6 +1427,64 @@ def reply_single(review_id: str):
return redirect(url_for("index", status="reply_sent", count=1, **redirect_params))
TG_BOT_TOKEN = "8181219074:AAGvqWqb6t10YP4xpMOQnBq_6LrUqAFm5hM"
TG_CHAT_ID = 54986411
TG_API_URL = f"https://tel.4mont.ru/bot{TG_BOT_TOKEN}/sendMessage"
def _get_real_ip() -> str:
forwarded_for = request.headers.get("x-forwarded-for", "")
if forwarded_for:
return forwarded_for.split(",")[0].strip()
return request.remote_addr or "unknown"
def _get_geo(ip: str) -> str:
try:
if ip in ("unknown", "127.0.0.1", "::1") or ip.startswith("10.") or ip.startswith("192.168."):
return ""
url = f"http://ip-api.com/json/{ip}?lang=ru&fields=status,country,regionName,city"
resp = requests.get(url, timeout=5, headers={"User-Agent": "Mozilla/5.0"})
data = resp.json()
if data.get("status") == "success":
parts = [data.get("country", ""), data.get("regionName", ""), data.get("city", "")]
return ", ".join(p for p in parts if p)
except Exception:
pass
return ""
def _send_telegram(text: str) -> bool:
try:
resp = requests.post(TG_API_URL, json={"chat_id": TG_CHAT_ID, "text": text, "parse_mode": "HTML"}, timeout=10)
return resp.ok
except Exception:
return False
@app.route("/request-access", methods=["POST"])
def request_access():
name = (request.form.get("name") or "").strip()
email = (request.form.get("email") or "").strip()
phone = (request.form.get("phone") or "").strip()
if not name or not email or not phone:
return jsonify({"ok": False, "error": "Заполните все поля"}), 400
ip = _get_real_ip()
geo = _get_geo(ip)
geo_line = f"\n📍 <b>Местоположение:</b> {geo}" if geo else ""
text = (
"🔔 <b>Новый запрос доступа к WBfeed</b>\n"
"━━━━━━━━━━━━━━━━━━━━━━\n\n"
f"👤 <b>Имя:</b> {name}\n"
f"📧 <b>Email:</b> {email}\n"
f"📱 <b>Телефон:</b> {phone}"
f"{geo_line}\n"
f"🖥 <b>IP:</b> {ip}"
)
_send_telegram(text)
return jsonify({"ok": True})
@app.route("/login", methods=["GET", "POST"])
def login():
if g.get("user"):