DBFahrerKaterchen3 commited on
Commit
be016d2
·
verified ·
1 Parent(s): 5e25370

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -27
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": {}, "roblox_codes": {}}, f)
43
 
44
 
45
  def load_db():
@@ -92,46 +91,63 @@ def login(user: dict):
92
 
93
 
94
  # -----------------------------
95
- # ROBLOX LOGIN START
96
  # -----------------------------
 
 
97
  @app.post("/auth/roblox/start")
98
  def roblox_start(data: dict):
99
- username = data["username"]
100
 
101
- code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
 
102
 
103
  db = load_db()
104
- db["roblox_codes"][username] = code
 
 
 
 
 
 
105
  save_db(db)
106
 
107
- return {"code": code}
 
108
 
109
 
110
- # -----------------------------
111
- # ROBLOX VERIFY
112
- # -----------------------------
113
- @app.post("/auth/roblox/verify")
114
- def roblox_verify(data: dict):
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
- code = db["roblox_codes"][username]
 
122
 
123
- # Roblox API: User suchen
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
- user_id = results[0]["id"]
 
130
 
131
- # Beschreibung abrufen
132
- desc = requests.get(f"https://users.roblox.com/v1/users/{user_id}").json().get("description", "")
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
- if code in desc:
135
- return {"success": True, "token": username}
136
 
137
- raise HTTPException(400, "Verification failed")
 
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}