feat: add session timeout configuration to Config class

This commit is contained in:
CaptainB 2025-06-28 19:43:40 +08:00
parent d4d7bdde41
commit 1dc6d6e8ba
2 changed files with 7 additions and 1 deletions

View File

@ -14,6 +14,7 @@ from django.core.cache import cache
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _
from maxkb.const import CONFIG
from common.auth.handle.auth_base_handle import AuthBaseHandle
from common.constants.authentication_type import AuthenticationType
from common.constants.cache_version import Cache_Version
@ -283,7 +284,9 @@ class UserToken(AuthBaseHandle):
if cache_token is None:
raise AppAuthenticationFailed(1002, _('Login expired'))
auth_details = get_token_details()
cache.touch(token, timeout=datetime.timedelta(seconds=60 * 60 * 2).seconds, version=version)
timeout = CONFIG.get_session_timeout()
print(timeout)
cache.touch(token, timeout=datetime.timedelta(seconds=timeout).seconds, version=version)
user = QuerySet(User).get(id=auth_details['id'])
auth = get_auth(user)
return user, auth

View File

@ -84,6 +84,9 @@ class Config(dict):
def get_log_level(self):
return self.get('LOG_LEVEL', 'DEBUG')
def get_session_timeout(self):
return int(self.get('SESSION_TIMEOUT', 25200))
def __init__(self, *args):
super().__init__(*args)