Server Fixes
This commit is contained in:
@@ -20,7 +20,6 @@ import base64
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from auth import router as auth_router, init_db, verify_jwt
|
||||
from pass_manager import activate_pass, has_active_pass, get_user_passes
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
@@ -826,49 +825,6 @@ async def proxy_status():
|
||||
}
|
||||
|
||||
|
||||
@app.post("/auth/pass/activate")
|
||||
async def api_activate_pass(request: Request):
|
||||
try:
|
||||
body = await request.json()
|
||||
pass_code = body.get("pass_code")
|
||||
if not pass_code:
|
||||
raise HTTPException(400, "pass_code обязателен")
|
||||
except:
|
||||
raise HTTPException(400, "Неверный JSON")
|
||||
|
||||
# Получаем текущего пользователя из токена
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
raise HTTPException(401, "Требуется авторизация")
|
||||
|
||||
token = auth_header.split(" ")[1]
|
||||
payload = verify_jwt(token) # функция из auth.py
|
||||
if not payload:
|
||||
raise HTTPException(401, "Недействительный токен")
|
||||
|
||||
result = activate_pass(pass_code, payload["username"], payload["sub"])
|
||||
|
||||
if result["success"]:
|
||||
return result
|
||||
else:
|
||||
raise HTTPException(400, result["error"])
|
||||
|
||||
|
||||
@app.get("/auth/pass/my")
|
||||
async def api_my_passes(request: Request):
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
raise HTTPException(401, "Требуется авторизация")
|
||||
|
||||
token = auth_header.split(" ")[1]
|
||||
payload = verify_jwt(token)
|
||||
if not payload:
|
||||
raise HTTPException(401, "Недействительный токен")
|
||||
|
||||
passes = get_user_passes(payload["username"])
|
||||
return {"passes": passes, "has_active": any(p["is_active"] for p in passes)}
|
||||
|
||||
|
||||
@app.exception_handler(Exception)
|
||||
async def global_exception_handler(request: Request, exc: Exception):
|
||||
logger.error("Unhandled exception", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user