Cleanup
This commit is contained in:
parent
96446226eb
commit
393096d0b7
1 changed files with 2 additions and 7 deletions
|
@ -27,10 +27,6 @@ class Token(BaseModel):
|
||||||
token_type: str
|
token_type: str
|
||||||
|
|
||||||
|
|
||||||
class TokenData(BaseModel):
|
|
||||||
username: str | None = None
|
|
||||||
|
|
||||||
|
|
||||||
# class User(BaseModel):
|
# class User(BaseModel):
|
||||||
# username: str
|
# username: str
|
||||||
# email: str | None = None
|
# email: str | None = None
|
||||||
|
@ -64,7 +60,7 @@ async def delete_user(session: AsyncSession, username: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
async def enable_user(session: AsyncSession, username: str, enable=True):
|
async def enable_user(session: AsyncSession, username: str, enable=True):
|
||||||
user_in_db: UserRead | None = await get_user(session, username)
|
user_in_db = await get_user(session, username)
|
||||||
if user_in_db is None:
|
if user_in_db is None:
|
||||||
raise SystemExit(f'User {username} does not exist in the database')
|
raise SystemExit(f'User {username} does not exist in the database')
|
||||||
user_in_db.disabled = not enable # type: ignore
|
user_in_db.disabled = not enable # type: ignore
|
||||||
|
@ -118,13 +114,12 @@ async def get_current_user(
|
||||||
username: str = payload.get("sub", '')
|
username: str = payload.get("sub", '')
|
||||||
if username == '':
|
if username == '':
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
token_data = TokenData(username=username)
|
|
||||||
except ExpiredSignatureError:
|
except ExpiredSignatureError:
|
||||||
raise expired_exception
|
raise expired_exception
|
||||||
except JWTError:
|
except JWTError:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
async with db_session() as session:
|
async with db_session() as session:
|
||||||
user = await get_user(session, username=token_data.username)
|
user = await get_user(session, username=username)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
return user
|
return user
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue