This commit is contained in:
2026-01-11 08:03:42 +03:00
parent 352ededf1c
commit 876e591e3b
2 changed files with 11 additions and 2 deletions

View File

@@ -106,8 +106,15 @@ async def create_invoice(req: BuyPlanRequest, request: Request):
return JSONResponse(status_code=500, content={"error": str(e)}) return JSONResponse(status_code=500, content={"error": str(e)})
@app.get("/api/user/{user_id}") @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) 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: if not user:
return JSONResponse(status_code=404, content={"error": "User not found"}) return JSONResponse(status_code=404, content={"error": "User not found"})

View File

@@ -379,7 +379,9 @@ async function loadDashboard() {
document.getElementById('user-name').textContent = currentState.user.first_name; document.getElementById('user-name').textContent = currentState.user.first_name;
try { 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) { if (res.status === 404) {
showInviteRequired(); showInviteRequired();