diff options
author | Parker <contact@pkrm.dev> | 2024-11-05 20:36:09 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-05 20:36:09 -0600 |
commit | e944df3d7d431b5bd88c2c235501a355ea1ba6ab (patch) | |
tree | 283a28cb77f2439d20ba00869de15cf65c2c450a /app/util/authentication.py | |
parent | 6f7e810916fd2de39d451886bbe18167e1784315 (diff) |
Fix auth and organization/standards
Diffstat (limited to 'app/util/authentication.py')
-rw-r--r-- | app/util/authentication.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/util/authentication.py b/app/util/authentication.py index 99f8b47..1127451 100644 --- a/app/util/authentication.py +++ b/app/util/authentication.py @@ -28,11 +28,11 @@ def verify_password(plain_password, hashed_password): ) -def get_user(db, id: int): +def get_user(db, username: str): """ Get the user object from the database """ - user = db.query(UserModel).filter(UserModel.id == id).first() + user = db.query(UserModel).filter(UserModel.username == username).first() if user: return UserInDB(**user.__dict__) @@ -46,6 +46,7 @@ def authenticate_user(db, username: str, password: str): if not user: return False if not verify_password(password, user.hashed_password): + print("WHY") return False return user @@ -121,8 +122,9 @@ async def get_current_user( try: payload = jwt.decode(token, secret_key, algorithms=[algorithm]) id: int = payload.get("sub") + username: str = payload.get("username") refresh: bool = payload.get("refresh") - if not id: + if not id or not username: return raise_unauthorized() # For some reason, an access token was passed when a refresh # token was expected - some likely malicious activity @@ -136,7 +138,7 @@ async def get_current_user( except InvalidTokenError: return raise_unauthorized() - user = get_user(db, id) + user = get_user(db, username) if user is None: return raise_unauthorized() |