From 1dc6d6e8bac0b57ec22e47e51b0332035bef1380 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Sat, 28 Jun 2025 19:43:40 +0800 Subject: [PATCH] feat: add session timeout configuration to Config class --- apps/common/auth/handle/impl/user_token.py | 5 ++++- apps/maxkb/conf.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/common/auth/handle/impl/user_token.py b/apps/common/auth/handle/impl/user_token.py index 879169e22..d69140eda 100644 --- a/apps/common/auth/handle/impl/user_token.py +++ b/apps/common/auth/handle/impl/user_token.py @@ -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 diff --git a/apps/maxkb/conf.py b/apps/maxkb/conf.py index 71fa4e87b..478718580 100644 --- a/apps/maxkb/conf.py +++ b/apps/maxkb/conf.py @@ -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)