feat: User -> Player
This commit is contained in:
parent
33c505fee4
commit
59e2fc4502
10
security.py
10
security.py
@ -5,7 +5,7 @@ from pydantic import BaseModel, ValidationError
|
|||||||
import jwt
|
import jwt
|
||||||
from jwt.exceptions import ExpiredSignatureError, InvalidTokenError
|
from jwt.exceptions import ExpiredSignatureError, InvalidTokenError
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
from db import engine, User
|
from db import engine, Player
|
||||||
from fastapi.security import (
|
from fastapi.security import (
|
||||||
OAuth2PasswordBearer,
|
OAuth2PasswordBearer,
|
||||||
OAuth2PasswordRequestForm,
|
OAuth2PasswordRequestForm,
|
||||||
@ -76,7 +76,7 @@ def get_user(username: str | None):
|
|||||||
try:
|
try:
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
return session.exec(
|
return session.exec(
|
||||||
select(User).where(User.username == username)
|
select(Player).where(User.username == username)
|
||||||
).one_or_none()
|
).one_or_none()
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
return
|
return
|
||||||
@ -150,7 +150,7 @@ async def get_current_user(
|
|||||||
|
|
||||||
|
|
||||||
async def get_current_active_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:
|
if current_user.disabled:
|
||||||
raise HTTPException(status_code=400, detail="Inactive user")
|
raise HTTPException(status_code=400, detail="Inactive user")
|
||||||
@ -188,12 +188,12 @@ async def logout(response: Response):
|
|||||||
|
|
||||||
|
|
||||||
async def read_users_me(
|
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
|
return current_user
|
||||||
|
|
||||||
|
|
||||||
async def read_own_items(
|
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}]
|
return [{"item_id": "Foo", "owner": current_user.username}]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user