Skip to content

Commit

Permalink
fix issue that caused the session not expire after user was deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
GammaC0de committed Jan 12, 2023
1 parent a7e1616 commit c035714
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/pyload/core/api/__init__.py
Expand Up @@ -1117,7 +1117,7 @@ def set_captcha_result(self, tid, result):
@permission(Perms.STATUS)
def get_events(self, uuid):
"""
Lists occured events, may be affected to changes in future.
Lists occurred events, may be affected to changes in the future.
:param uuid:
:return: list of `Events`
Expand Down Expand Up @@ -1230,6 +1230,15 @@ def check_auth(self, username, password):
"""
return self.pyload.db.check_auth(username, password)

def user_exists(self, username):
"""
Check if a user actually exists in the database.
:param username:
:return: boolean
"""
return self.pyload.db.user_exists(username)

@legacy("isAuthorized")
def is_authorized(self, func, userdata):
"""
Expand Down
5 changes: 5 additions & 0 deletions src/pyload/core/database/user_database.py
Expand Up @@ -92,6 +92,11 @@ def set_permission(self, user, perms):
def set_role(self, user, role):
self.c.execute("UPDATE users SET role=? WHERE name=?", (role, user))

@style.queue
def user_exists(self, user):
self.c.execute("SELECT name FROM users WHERE name=?", (user,))
return self.c.fetchone() is not None

@style.queue
def list_users(self):
self.c.execute("SELECT name FROM users")
Expand Down
8 changes: 5 additions & 3 deletions src/pyload/webui/app/helpers.py
Expand Up @@ -164,9 +164,11 @@ def wrapper(*args, **kwargs):


def is_authenticated(session=flask.session):
return session.get("name") and session.get(
"authenticated"
) # NOTE: why checks name?
api = flask.current_app.config["PYLOAD_API"]
user = session.get("name")
authenticated = session.get("authenticated")

return authenticated and api.user_exists(user)


def login_required(perm):
Expand Down

0 comments on commit c035714

Please sign in to comment.