Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,10 +36,9 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
| 36 |
|
| 37 |
DB_FILE = "users.json"
|
| 38 |
|
| 39 |
-
# Falls Datei nicht existiert → erstellen
|
| 40 |
if not os.path.exists(DB_FILE):
|
| 41 |
with open(DB_FILE, "w") as f:
|
| 42 |
-
json.dump({"users": {}, "
|
| 43 |
|
| 44 |
|
| 45 |
def load_db():
|
|
@@ -92,46 +91,63 @@ def login(user: dict):
|
|
| 92 |
|
| 93 |
|
| 94 |
# -----------------------------
|
| 95 |
-
# ROBLOX
|
| 96 |
# -----------------------------
|
|
|
|
|
|
|
| 97 |
@app.post("/auth/roblox/start")
|
| 98 |
def roblox_start(data: dict):
|
| 99 |
-
username = data["username"]
|
| 100 |
|
| 101 |
-
|
|
|
|
| 102 |
|
| 103 |
db = load_db()
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
save_db(db)
|
| 106 |
|
| 107 |
-
|
|
|
|
| 108 |
|
| 109 |
|
| 110 |
-
# --
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
username = data["username"]
|
| 116 |
|
| 117 |
db = load_db()
|
| 118 |
-
if username not in db["roblox_codes"]:
|
| 119 |
-
raise HTTPException(400, "No verification started")
|
| 120 |
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
r = requests.get(f"https://users.roblox.com/v1/users/search?keyword={username}")
|
| 125 |
-
results = r.json().get("data", [])
|
| 126 |
-
if not results:
|
| 127 |
-
raise HTTPException(400, "User not found")
|
| 128 |
|
| 129 |
-
|
|
|
|
| 130 |
|
| 131 |
-
#
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
if
|
| 135 |
-
return {"
|
| 136 |
|
| 137 |
-
|
|
|
|
| 36 |
|
| 37 |
DB_FILE = "users.json"
|
| 38 |
|
|
|
|
| 39 |
if not os.path.exists(DB_FILE):
|
| 40 |
with open(DB_FILE, "w") as f:
|
| 41 |
+
json.dump({"users": {}, "roblox_pending": {}, "roblox_verified": {}}, f)
|
| 42 |
|
| 43 |
|
| 44 |
def load_db():
|
|
|
|
| 91 |
|
| 92 |
|
| 93 |
# -----------------------------
|
| 94 |
+
# ROBLOX GAME-JOIN LOGIN
|
| 95 |
# -----------------------------
|
| 96 |
+
|
| 97 |
+
# 1) User startet Verifizierung auf der Website
|
| 98 |
@app.post("/auth/roblox/start")
|
| 99 |
def roblox_start(data: dict):
|
| 100 |
+
username = data["username"].strip()
|
| 101 |
|
| 102 |
+
if not username:
|
| 103 |
+
raise HTTPException(400, "Username required")
|
| 104 |
|
| 105 |
db = load_db()
|
| 106 |
+
|
| 107 |
+
code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
|
| 108 |
+
|
| 109 |
+
db["roblox_pending"][username.lower()] = {
|
| 110 |
+
"code": code,
|
| 111 |
+
"verified": False
|
| 112 |
+
}
|
| 113 |
save_db(db)
|
| 114 |
|
| 115 |
+
# Diesen Code zeigst du dem User auf der Website
|
| 116 |
+
return {"success": True, "code": code}
|
| 117 |
|
| 118 |
|
| 119 |
+
# 2) Roblox-Game bestätigt Join (wird vom Roblox-Script aufgerufen)
|
| 120 |
+
@app.post("/auth/roblox/confirm")
|
| 121 |
+
def roblox_confirm(data: dict):
|
| 122 |
+
username = data["username"].strip().lower()
|
| 123 |
+
code = data["code"].strip()
|
|
|
|
| 124 |
|
| 125 |
db = load_db()
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
if username not in db["roblox_pending"]:
|
| 128 |
+
raise HTTPException(400, "No pending verification for this user")
|
| 129 |
|
| 130 |
+
entry = db["roblox_pending"][username]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
if entry["code"] != code:
|
| 133 |
+
raise HTTPException(400, "Invalid code")
|
| 134 |
|
| 135 |
+
# Verifiziert
|
| 136 |
+
db["roblox_verified"][username] = True
|
| 137 |
+
del db["roblox_pending"][username]
|
| 138 |
+
save_db(db)
|
| 139 |
+
|
| 140 |
+
return {"success": True}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# 3) Website fragt regelmäßig ab, ob User verifiziert ist
|
| 144 |
+
@app.post("/auth/roblox/status")
|
| 145 |
+
def roblox_status(data: dict):
|
| 146 |
+
username = data["username"].strip().lower()
|
| 147 |
+
|
| 148 |
+
db = load_db()
|
| 149 |
|
| 150 |
+
if username in db["roblox_verified"]:
|
| 151 |
+
return {"verified": True, "token": username}
|
| 152 |
|
| 153 |
+
return {"verified": False}
|