21 lines
702 B
Python
21 lines
702 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from core.database import get_db
|
|
from models.user import User
|
|
from schemas.user import UserLoginSchema, UserResponse
|
|
from helpers.auth_helpers import validate_user_credentials
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/login", status_code=200, response_model=UserResponse)
|
|
async def login(
|
|
credentials: UserLoginSchema,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
user = validate_user_credentials(db, credentials.userId, credentials.password)
|
|
if not user:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Invalid credentials"
|
|
)
|
|
return user |