user-profiles: Cross-Channel-Identität mit Registrierung, Login, Profil + WhatsApp/Telegram-Flow
This commit is contained in:
+89
-3
@@ -194,6 +194,91 @@ def telegram_webhook():
|
||||
spiel_titel = None
|
||||
category_override = None
|
||||
|
||||
# ── Nutzer-Registrierung per Telegram ──────────────────────────
|
||||
pending_codes = getattr(app, '_tg_pending_codes', {})
|
||||
if msg_type == "text":
|
||||
clean = content.strip().lower()
|
||||
if clean == "registrieren":
|
||||
import random
|
||||
code = str(random.randint(100000, 999999))
|
||||
pending_codes[sender_id] = code
|
||||
app._tg_pending_codes = pending_codes
|
||||
if TELEGRAM_TOKEN:
|
||||
import requests as _r
|
||||
try:
|
||||
_r.post(
|
||||
"{}/sendMessage".format(TELEGRAM_API),
|
||||
json={"chat_id": int(sender_id),
|
||||
"text": "🔐 Dein Verifikationscode: *{}*\n\n"
|
||||
"Antworte einfach mit: code {}".format(code, code)},
|
||||
timeout=10,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return "OK", 200
|
||||
if clean.startswith("code ") and len(clean) >= 10:
|
||||
entered = clean[5:].strip()
|
||||
if sender_id in pending_codes and pending_codes[sender_id] == entered:
|
||||
del pending_codes[sender_id]
|
||||
app._tg_pending_codes = pending_codes
|
||||
if TELEGRAM_TOKEN:
|
||||
import requests as _r
|
||||
try:
|
||||
_r.post(
|
||||
"{}/sendMessage".format(TELEGRAM_API),
|
||||
json={"chat_id": int(sender_id),
|
||||
"text": "✅ Du bist verifiziert! Welche Telefonnummer hast du? "
|
||||
"Antworte einfach mit: phone +49152..."},
|
||||
timeout=10,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
if TELEGRAM_TOKEN:
|
||||
import requests as _r
|
||||
try:
|
||||
_r.post(
|
||||
"{}/sendMessage".format(TELEGRAM_API),
|
||||
json={"chat_id": int(sender_id),
|
||||
"text": "❌ Falscher Code. Schick \"registrieren\" für einen neuen."},
|
||||
timeout=10,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return "OK", 200
|
||||
# "phone +49..." → Telefonnummer verknüpfen
|
||||
if clean.startswith("phone ") or clean.startswith("+49"):
|
||||
phone = clean[6:].strip() if clean.startswith("phone ") else clean.strip()
|
||||
# Normalize: remove spaces
|
||||
phone = phone.replace(" ", "").replace("-", "")
|
||||
existing = db.execute("SELECT id FROM users WHERE phone=?", (phone,)).fetchone()
|
||||
if existing:
|
||||
db.execute("UPDATE users SET name=? WHERE phone=?",
|
||||
(sender_name, phone))
|
||||
else:
|
||||
db.execute("INSERT INTO users (phone, name, verified) VALUES (?,?,1)",
|
||||
(phone, sender_name))
|
||||
db.commit()
|
||||
if TELEGRAM_TOKEN:
|
||||
import requests as _r
|
||||
try:
|
||||
_r.post(
|
||||
"{}/sendMessage".format(TELEGRAM_API),
|
||||
json={"chat_id": int(sender_id),
|
||||
"text": "✅ Deine Telefonnummer ist jetzt verknüpft! "
|
||||
"Dein Profil: https://chat.datenhimmel.work/profile"},
|
||||
timeout=10,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return "OK", 200
|
||||
|
||||
# ── Cross-Channel: User ueber Telegram-ID + phone verknuepfung ─
|
||||
user_row = db.execute(
|
||||
"SELECT id, name FROM users WHERE phone=?",
|
||||
(sender_id,), # Telegram-ID als Fallback
|
||||
).fetchone()
|
||||
|
||||
if "#out" in content.lower():
|
||||
category_override = "ausverkauft"
|
||||
idx = content.lower().find("#out")
|
||||
@@ -256,9 +341,10 @@ def telegram_webhook():
|
||||
cat = category_override or None
|
||||
db.execute(
|
||||
"""INSERT INTO submissions
|
||||
(channel, sender_id, sender_name, type, content, media_path, status, halle, category, spiel_titel)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 'new', ?, ?, ?)""",
|
||||
("telegram", sender_id, sender_name, msg_type, content, media_path, halle, cat, spiel_titel),
|
||||
(channel, sender_id, sender_name, type, content, media_path, status, halle, category, spiel_titel, user_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 'new', ?, ?, ?, ?)""",
|
||||
("telegram", sender_id, sender_name, msg_type, content, media_path, halle, cat, spiel_titel,
|
||||
user_row["id"] if user_row else None),
|
||||
)
|
||||
if cat == "ausverkauft" and spiel_titel:
|
||||
mark_ausverkauft_in_neuheiten(db, spiel_titel)
|
||||
|
||||
Reference in New Issue
Block a user