feat: User -> Player

This commit is contained in:
julius 2025-03-10 11:24:03 +01:00
parent 33c505fee4
commit 59e2fc4502
Signed by: julius
GPG Key ID: C80A63E6A5FD7092

View File

@ -5,7 +5,7 @@ from pydantic import BaseModel, ValidationError
import jwt
from jwt.exceptions import ExpiredSignatureError, InvalidTokenError
from sqlmodel import Session, select
from db import engine, User
from db import engine, Player
from fastapi.security import (
OAuth2PasswordBearer,
OAuth2PasswordRequestForm,
@ -76,7 +76,7 @@ def get_user(username: str | None):
try:
with Session(engine) as session:
return session.exec(
select(User).where(User.username == username)
select(Player).where(User.username == username)
).one_or_none()
except OperationalError:
return
@ -150,7 +150,7 @@ async def get_current_user(
async def get_current_active_user(
current_user: Annotated[User, Depends(get_current_user)],
current_user: Annotated[Player, Depends(get_current_user)],
):
if current_user.disabled:
raise HTTPException(status_code=400, detail="Inactive user")
@ -188,12 +188,12 @@ async def logout(response: Response):
async def read_users_me(
current_user: Annotated[User, Depends(get_current_active_user)],
current_user: Annotated[Player, Depends(get_current_active_user)],
):
return current_user
async def read_own_items(
current_user: Annotated[User, Depends(get_current_active_user)],
current_user: Annotated[Player, Depends(get_current_active_user)],
):
return [{"item_id": "Foo", "owner": current_user.username}]