diff --git a/server.py b/server.py index 11cc5bf..15f2504 100644 --- a/server.py +++ b/server.py @@ -106,8 +106,15 @@ async def create_invoice(req: BuyPlanRequest, request: Request): return JSONResponse(status_code=500, content={"error": str(e)}) @app.get("/api/user/{user_id}") -async def get_user_stats(user_id: int): +async def get_user_stats(user_id: int, username: str = "Unknown", lang: str = "en"): user = await db.get_user(user_id) + + # Auto-register admin if not exists + if not user and user_id in CONFIG["ADMIN_IDS"]: + marzban_username = username.lower() if username and username != "Unknown" else f"admin_{user_id}" + await db.create_user(user_id, username, marzban_username) + user = await db.get_user(user_id) + if not user: return JSONResponse(status_code=404, content={"error": "User not found"}) diff --git a/web_app/static/js/app.js b/web_app/static/js/app.js index bb0c7e7..612aa88 100644 --- a/web_app/static/js/app.js +++ b/web_app/static/js/app.js @@ -379,7 +379,9 @@ async function loadDashboard() { document.getElementById('user-name').textContent = currentState.user.first_name; try { - const res = await fetch(`${API_BASE}/user/${currentState.user.id}`); + const username = currentState.user.username || ''; + const lang = currentState.lang || 'en'; + const res = await fetch(`${API_BASE}/user/${currentState.user.id}?username=${encodeURIComponent(username)}&lang=${lang}`); if (res.status === 404) { showInviteRequired();