File size: 3,956 Bytes
e8b014c
9f65957
191a32f
e8b014c
9f65957
 
 
c2c387e
9f65957
 
 
 
 
 
 
 
 
 
 
 
 
 
339c1cb
9f65957
191a32f
e8b014c
 
 
 
191a32f
e8b014c
 
 
 
 
 
 
 
 
 
be016d2
e8b014c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be016d2
e8b014c
be016d2
 
e8b014c
 
be016d2
e8b014c
be016d2
 
e8b014c
 
be016d2
 
 
 
 
 
 
e8b014c
 
be016d2
 
e8b014c
 
be016d2
 
 
 
 
e8b014c
 
 
be016d2
 
e8b014c
be016d2
e8b014c
be016d2
 
e8b014c
be016d2
 
 
 
 
 
 
 
 
 
 
 
 
 
e8b014c
be016d2
 
e8b014c
be016d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
# -----------------------------
@app.get("/")
def serve_html():
    return FileResponse("index.html")


# -----------------------------
# 2) Kontaktformular verarbeiten
# -----------------------------
@app.post("/send")
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
# -----------------------------
@app.post("/auth/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
# -----------------------------
@app.post("/auth/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
@app.post("/auth/roblox/start")
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)
@app.post("/auth/roblox/confirm")
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
@app.post("/auth/roblox/status")
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}