From d5fe8809b27a9b90a6d5a27ee2c2de7e124f284a Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 28 Mar 2025 18:55:39 +0000 Subject: [PATCH] Update code in endpoints/login.post.py --- endpoints/login.post.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/endpoints/login.post.py b/endpoints/login.post.py index 0d3d39f..cedeb81 100644 --- a/endpoints/login.post.py +++ b/endpoints/login.post.py @@ -2,23 +2,20 @@ 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 UserLogin, UserResponse -from helpers.auth_helpers import authenticate_user, create_access_token +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( - login_data: UserLogin, + credentials: UserLoginSchema, db: Session = Depends(get_db) ): - user = authenticate_user(db, login_data.username, login_data.password) + user = validate_user_credentials(db, credentials.userId, credentials.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect username or password", - headers={"WWW-Authenticate": "Bearer"}, + detail="Invalid credentials" ) - - access_token = create_access_token(data={"sub": user.username}) - return {"access_token": access_token, "token_type": "bearer"} \ No newline at end of file + return user \ No newline at end of file