24 lines
781 B
Python
24 lines
781 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from core.database import get_db
|
|
from models.proxy import Proxy
|
|
from schemas.proxy import ProxySchema, ProxyLogin
|
|
from helpers.proxy_helpers import authenticate_proxy, create_proxy_session
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/login", status_code=200, response_model=ProxySchema)
|
|
async def login_proxy(
|
|
proxy_data: ProxyLogin,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
proxy_session = authenticate_proxy(db, proxy_data)
|
|
if not proxy_session:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Invalid credentials"
|
|
)
|
|
|
|
session = create_proxy_session(db, proxy_session)
|
|
return session |