Files
vpn-control-panel/app/api/v1/auth.py
smolkik-code 7c7c88621d Initial commit: VPN Control Panel
- FastAPI REST API with JWT auth
- aiogram 3 Telegram bot with admin middleware
- APScheduler daily tasks (expiry, reminders, revoke, sync)
- SQLAlchemy 2 async ORM with Alembic migrations
- Jinja2 admin panel (Dashboard, Users, Payments, Servers, Tariffs)
- VPN provider abstraction with MockProvider
- Stats service with revenue/subscription analytics
- Docker Compose (PostgreSQL + Redis + app)
- Healthcheck endpoint
2026-07-05 17:50:11 +07:00

36 lines
1.0 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, status
from app.api.deps import get_auth_service
from app.schemas.auth import LoginRequest, RefreshRequest, TokenResponse
from app.services.auth import AuthService
router = APIRouter(prefix="/auth", tags=["Auth"])
@router.post("/login", response_model=TokenResponse)
async def login(
body: LoginRequest,
auth_svc: AuthService = Depends(get_auth_service),
):
result = await auth_svc.authenticate(body.telegram_id, body.secret_key)
if result is None:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid credentials",
)
return result
@router.post("/refresh", response_model=TokenResponse)
async def refresh(
body: RefreshRequest,
auth_svc: AuthService = Depends(get_auth_service),
):
try:
return auth_svc.refresh_access_token(body.refresh_token)
except ValueError as e:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=str(e),
)