2025-03-29 19:34:07 +00:00

24 lines
765 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.user import User
from schemas.user import UserSchema, UserCreate
from helpers.auth_helpers import authenticate_user
router = APIRouter()
@router.post("/login", status_code=200)
async def login(
username: str,
password: str,
db: Session = Depends(get_db)
):
user = authenticate_user(db, username, password)
if not user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
return {"access_token": "token", "token_type": "bearer"}