Spaces:
Sleeping
Sleeping
Download app.py from RSBtech/RSBtechHub: direct link, hf CLI and curl.
- Browser
- Download file 3.96 kB
-
https://huggingface.co/spaces/RSBtech/RSBtechHub/resolve/main/app.py
- Command line
-
hf download hf://spaces/RSBtech/RSBtechHub/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RSBtech/RSBtechHub/resolve/main/app.py
3.96 kB
| from fastapi import FastAPI, Form, HTTPException | |
| from fastapi.responses import FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| import requests, json, os, bcrypt, random, string | |
| app = FastAPI() | |
| WEBHOOK = "https://discordapp.com/api/webhooks/1466862736460873779/MHJRqqiA9nua9i1I825gaFf2KO5rSQvqyRSSFzUYqaoPZLtrPkgJ9DuP_aDBI03LvAE0" | |
| # ----------------------------- | |
| # 1) index.html ausliefern | |
| # ----------------------------- | |
| def serve_html(): | |
| return FileResponse("index.html") | |
| # ----------------------------- | |
| # 2) Kontaktformular verarbeiten | |
| # ----------------------------- | |
| def send(name: str = Form(...), message: str = Form(...)): | |
| requests.post(WEBHOOK, json={"content": f"# Neue Kontaktanfrage\n**Von** {name}:\n**Nachricht**:\n{message}"}) | |
| return {"status": "ok"} | |
| # ----------------------------- | |
| # STATIC FILES | |
| # ----------------------------- | |
| app.mount("/static", StaticFiles(directory="static"), name="static") | |
| # ----------------------------- | |
| # LOGIN SYSTEM | |
| # ----------------------------- | |
| DB_FILE = "users.json" | |
| if not os.path.exists(DB_FILE): | |
| with open(DB_FILE, "w") as f: | |
| json.dump({"users": {}, "roblox_pending": {}, "roblox_verified": {}}, f) | |
| def load_db(): | |
| with open(DB_FILE, "r") as f: | |
| return json.load(f) | |
| def save_db(data): | |
| with open(DB_FILE, "w") as f: | |
| json.dump(data, f, indent=4) | |
| # ----------------------------- | |
| # EMAIL REGISTER | |
| # ----------------------------- | |
| def register(user: dict): | |
| db = load_db() | |
| email = user["email"] | |
| password = user["password"] | |
| if email in db["users"]: | |
| raise HTTPException(400, "Email already exists") | |
| hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode() | |
| db["users"][email] = {"password": hashed} | |
| save_db(db) | |
| return {"success": True} | |
| # ----------------------------- | |
| # EMAIL LOGIN | |
| # ----------------------------- | |
| def login(user: dict): | |
| db = load_db() | |
| email = user["email"] | |
| password = user["password"] | |
| if email not in db["users"]: | |
| raise HTTPException(400, "User not found") | |
| hashed = db["users"][email]["password"].encode() | |
| if not bcrypt.checkpw(password.encode(), hashed): | |
| raise HTTPException(400, "Wrong password") | |
| return {"success": True, "token": email} | |
| # ----------------------------- | |
| # ROBLOX GAME-JOIN LOGIN | |
| # ----------------------------- | |
| # 1) User startet Verifizierung auf der Website | |
| def roblox_start(data: dict): | |
| username = data["username"].strip() | |
| if not username: | |
| raise HTTPException(400, "Username required") | |
| db = load_db() | |
| code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) | |
| db["roblox_pending"][username.lower()] = { | |
| "code": code, | |
| "verified": False | |
| } | |
| save_db(db) | |
| # Diesen Code zeigst du dem User auf der Website | |
| return {"success": True, "code": code} | |
| # 2) Roblox-Game bestätigt Join (wird vom Roblox-Script aufgerufen) | |
| def roblox_confirm(data: dict): | |
| username = data["username"].strip().lower() | |
| code = data["code"].strip() | |
| db = load_db() | |
| if username not in db["roblox_pending"]: | |
| raise HTTPException(400, "No pending verification for this user") | |
| entry = db["roblox_pending"][username] | |
| if entry["code"] != code: | |
| raise HTTPException(400, "Invalid code") | |
| # Verifiziert | |
| db["roblox_verified"][username] = True | |
| del db["roblox_pending"][username] | |
| save_db(db) | |
| return {"success": True} | |
| # 3) Website fragt regelmäßig ab, ob User verifiziert ist | |
| def roblox_status(data: dict): | |
| username = data["username"].strip().lower() | |
| db = load_db() | |
| if username in db["roblox_verified"]: | |
| return {"verified": True, "token": username} | |
| return {"verified": False} | |