feat: Support session_timeout parameter (#3697)

This commit is contained in:
shaohuzhang1 2025-07-22 10:35:20 +08:00 committed by GitHub
parent 1ee0eac455
commit 0531a6ecc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -6,18 +6,18 @@
@date2024/3/14 03:02
@desc: 用户认证
"""
from django.core import cache
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _
from common.auth.handle.auth_base_handle import AuthBaseHandle
from common.constants.authentication_type import AuthenticationType
from common.constants.permission_constants import RoleConstants, get_permission_list_by_role, Auth
from common.exception.app_exception import AppAuthenticationFailed
from smartdoc.settings import JWT_AUTH
from smartdoc.const import CONFIG
from users.models import User
from django.core import cache
from users.models.user import get_user_dynamics_permission
from django.utils.translation import gettext_lazy as _
token_cache = cache.caches['token_cache']
@ -35,7 +35,7 @@ class UserToken(AuthBaseHandle):
auth_details = get_token_details()
user = QuerySet(User).get(id=auth_details['id'])
# 续期
token_cache.touch(token, timeout=JWT_AUTH['JWT_EXPIRATION_DELTA'].total_seconds())
token_cache.touch(token, timeout=CONFIG.get_session_timeout())
rule = RoleConstants[user.role]
permission_list = get_permission_list_by_role(RoleConstants[user.role])
# 获取用户的应用和知识库的权限

View File

@ -7,6 +7,7 @@
2. 程序需要, 用户不需要更改的写到settings中
3. 程序需要, 用户需要更改的写到本config中
"""
import datetime
import errno
import logging
import os
@ -119,6 +120,9 @@ class Config(dict):
}
}
def get_session_timeout(self):
return datetime.timedelta(seconds=self.get('SESSION_TIMEOUT', 28800))
def get_language_code(self):
return self.get('LANGUAGE_CODE', 'zh-CN')

View File

@ -22,7 +22,7 @@ from common.constants.permission_constants import PermissionConstants, CompareCo
from common.log.log import log
from common.response import result
from common.util.common import encryption
from smartdoc.settings import JWT_AUTH
from smartdoc.const import CONFIG
from users.serializers.user_serializers import RegisterSerializer, LoginSerializer, CheckCodeSerializer, \
RePasswordSerializer, \
SendEmailSerializer, UserProfile, UserSerializer, UserManageSerializer, UserInstanceSerializer, SystemSerializer, \
@ -199,7 +199,7 @@ class Login(APIView):
# 校验请求参数
user = login_request.is_valid(raise_exception=True)
token = login_request.get_user_token()
token_cache.set(token, user, timeout=JWT_AUTH['JWT_EXPIRATION_DELTA'])
token_cache.set(token, user, timeout=CONFIG.get_session_timeout())
return result.success(token)