Update code in endpoints/login.post.py
This commit is contained in:
parent
0c0d8dd2a6
commit
41551584c0
@ -3,21 +3,22 @@ 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, UserLogin
|
||||
from helpers.user_helpers import authenticate_user
|
||||
from schemas.user import UserSchema, UserCreate
|
||||
from helpers.auth_helpers import authenticate_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/login", status_code=200, response_model=UserSchema)
|
||||
@router.post("/login", status_code=200)
|
||||
async def login(
|
||||
user_data: UserLogin,
|
||||
username: str,
|
||||
password: str,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
user = authenticate_user(db, user_data.email, user_data.password)
|
||||
user = authenticate_user(db, username, password)
|
||||
if not user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Incorrect email or password",
|
||||
detail="Incorrect username or password",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
return user
|
||||
return {"access_token": "token", "token_type": "bearer"}
|
Loading…
x
Reference in New Issue
Block a user