Work on game form

This commit is contained in:
2024-05-26 20:39:59 +04:00
parent 2f8d1e5f47
commit fe424182df
2 changed files with 5 additions and 2 deletions

View File

@@ -45,9 +45,11 @@ async def get_user(token: str = Depends(oauth2_scheme),
try: try:
payload = jwt.decode(token, SECRET_KEY) payload = jwt.decode(token, SECRET_KEY)
token_data = TokenData(**payload) token_data = TokenData(**payload)
except Exception: except Exception as e:
print(e)
raise credentials_exception raise credentials_exception
user = await db.get_user(db_session, token_data.username) user = await db.get_user(db_session, token_data.username)
print(user)
if user is None: if user is None:
raise credentials_exception raise credentials_exception
return user return user
@@ -59,7 +61,7 @@ def create_token(user: db.User):
expire = datetime.now(timezone.utc) + access_token_expires expire = datetime.now(timezone.utc) + access_token_expires
to_encode = { to_encode = {
"id": user.id, "id": user.id,
"name": user.name, "username": user.name,
"email": user.email, "email": user.email,
"expire": str(expire) "expire": str(expire)
} }

View File

@@ -51,6 +51,7 @@ async def delete_game(game_id: int,
user: db.User = Depends(get_user), user: db.User = Depends(get_user),
db_session: AsyncSession = Depends(db.get_session)): db_session: AsyncSession = Depends(db.get_session)):
game_db = await db.get_game(db_session, game_id) game_db = await db.get_game(db_session, game_id)
print(game_db)
if (game_db is None): if (game_db is None):
raise HTTPException(status.HTTP_404_NOT_FOUND, raise HTTPException(status.HTTP_404_NOT_FOUND,
detail=f"Game with id={game_id} not found") detail=f"Game with id={game_id} not found")