skill-forge/API/app/controllers/auth_router.py

28 lines
695 B
Python

from fastapi import APIRouter, HTTPException
from fastapi.params import Depends
from sqlalchemy.orm import Session
from app.database.dependencies import get_db
from app.domain.entities.auth_entity import AuthEntity
from app.infrastructure.auth_service import AuthService
router = APIRouter()
@router.get("/login/", response_model=dict)
def login(
auth_data: AuthEntity,
db: Session = Depends(get_db)
):
auth_service = AuthService(db)
token = auth_service.authenticate(auth_data.login, auth_data.password)
if token is None:
raise HTTPException(
status_code=401,
detail="Incorrect username or password"
)
return token