Skip to content

Commit 1bad968

Browse files
committed
feat: Support session_timeout parameter
1 parent 1ee0eac commit 1bad968

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

apps/common/auth/handle/impl/user_token.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
@date:2024/3/14 03:02
77
@desc: 用户认证
88
"""
9+
from django.core import cache
910
from django.db.models import QuerySet
11+
from django.utils.translation import gettext_lazy as _
1012

1113
from common.auth.handle.auth_base_handle import AuthBaseHandle
1214
from common.constants.authentication_type import AuthenticationType
1315
from common.constants.permission_constants import RoleConstants, get_permission_list_by_role, Auth
1416
from common.exception.app_exception import AppAuthenticationFailed
15-
from smartdoc.settings import JWT_AUTH
17+
from smartdoc.const import CONFIG
1618
from users.models import User
17-
from django.core import cache
18-
1919
from users.models.user import get_user_dynamics_permission
20-
from django.utils.translation import gettext_lazy as _
20+
2121
token_cache = cache.caches['token_cache']
2222

2323

@@ -35,7 +35,7 @@ def handle(self, request, token: str, get_token_details):
3535
auth_details = get_token_details()
3636
user = QuerySet(User).get(id=auth_details['id'])
3737
# 续期
38-
token_cache.touch(token, timeout=JWT_AUTH['JWT_EXPIRATION_DELTA'].total_seconds())
38+
token_cache.touch(token, timeout=CONFIG.get_session_timeout())
3939
rule = RoleConstants[user.role]
4040
permission_list = get_permission_list_by_role(RoleConstants[user.role])
4141
# 获取用户的应用和知识库的权限

apps/smartdoc/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
2. 程序需要, 用户不需要更改的写到settings中
88
3. 程序需要, 用户需要更改的写到本config中
99
"""
10+
import datetime
1011
import errno
1112
import logging
1213
import os
@@ -119,6 +120,9 @@ def get_db_setting(self) -> dict:
119120
}
120121
}
121122

123+
def get_session_timeout(self):
124+
return datetime.timedelta(seconds=self.get('SESSION_TIMEOUT', 28800))
125+
122126
def get_language_code(self):
123127
return self.get('LANGUAGE_CODE', 'zh-CN')
124128

apps/users/views/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from common.log.log import log
2323
from common.response import result
2424
from common.util.common import encryption
25-
from smartdoc.settings import JWT_AUTH
25+
from smartdoc.const import CONFIG
2626
from users.serializers.user_serializers import RegisterSerializer, LoginSerializer, CheckCodeSerializer, \
2727
RePasswordSerializer, \
2828
SendEmailSerializer, UserProfile, UserSerializer, UserManageSerializer, UserInstanceSerializer, SystemSerializer, \
@@ -199,7 +199,7 @@ def post(self, request: Request):
199199
# 校验请求参数
200200
user = login_request.is_valid(raise_exception=True)
201201
token = login_request.get_user_token()
202-
token_cache.set(token, user, timeout=JWT_AUTH['JWT_EXPIRATION_DELTA'])
202+
token_cache.set(token, user, timeout=CONFIG.get_session_timeout())
203203
return result.success(token)
204204

205205

0 commit comments

Comments
 (0)