mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 13:03:02 +00:00
fix auth
This commit is contained in:
@@ -112,6 +112,8 @@ class UserSessionService:
|
||||
|
||||
def __init__(self):
|
||||
self.cache = DragonflyCache("sessions")
|
||||
# Backward compatibility for older call sites.
|
||||
self.session_cache = self.cache
|
||||
|
||||
def create_session(
|
||||
self, session_token: str, user_data: dict[str, Any], ttl_hours: int = 24
|
||||
@@ -119,6 +121,17 @@ class UserSessionService:
|
||||
"""Create user session"""
|
||||
return self.cache.set(f"session:{session_token}", user_data, ttl_hours)
|
||||
|
||||
def set_user_session(
|
||||
self, userid: int, user_data: dict[str, Any], ttl_seconds: int = 24 * 3600
|
||||
):
|
||||
"""Store latest session payload by user id for quick lookups."""
|
||||
ttl_hours = max(1, int(ttl_seconds // 3600))
|
||||
return self.cache.set(f"user_session:{userid}", user_data, ttl_hours)
|
||||
|
||||
def get_user_session(self, userid: int) -> dict[str, Any] | None:
|
||||
"""Get latest session payload for a user id."""
|
||||
return self.cache.get(f"user_session:{userid}")
|
||||
|
||||
def get_session(self, session_token: str) -> dict[str, Any] | None:
|
||||
"""Get user session"""
|
||||
return self.cache.get(f"session:{session_token}")
|
||||
@@ -131,6 +144,10 @@ class UserSessionService:
|
||||
"""Invalidate user session"""
|
||||
return self.cache.delete(f"session:{session_token}")
|
||||
|
||||
def invalidate_user_session(self, userid: int):
|
||||
"""Invalidate latest session payload for a user id."""
|
||||
return self.cache.delete(f"user_session:{userid}")
|
||||
|
||||
def get_user_sessions(self, userid: int) -> list[str]:
|
||||
"""Get all active sessions for user"""
|
||||
pattern = "session:*"
|
||||
|
||||
Reference in New Issue
Block a user