U 新增会话过期时间配置TOKEN_TTL

pull/517/head
vapao 2022-06-27 14:04:13 +08:00
parent 9ba9f5782e
commit 833b49a822
3 changed files with 5 additions and 4 deletions

View File

@ -2,6 +2,7 @@
# Copyright: (c) <spug.dev@gmail.com>
# Released under the AGPL-3.0 License.
from django.core.cache import cache
from django.conf import settings
from libs.mixins import AdminView, View
from libs import JsonParser, Argument, human_datetime, json_response
from libs.utils import get_request_real_ip, generate_random_str
@ -245,7 +246,7 @@ def handle_user_info(request, user, captcha):
x_real_ip = get_request_real_ip(request.headers)
token_isvalid = user.access_token and len(user.access_token) == 32 and user.token_expired >= time.time()
user.access_token = user.access_token if token_isvalid else uuid.uuid4().hex
user.token_expired = time.time() + 8 * 60 * 60
user.token_expired = time.time() + settings.TOKEN_TTL
user.last_login = human_datetime()
user.last_ip = x_real_ip
user.save()

View File

@ -155,11 +155,10 @@ class SSH:
command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n'
command = self._handle_command(command, self.default_env)
self.channel.sendall(command)
out = line = ''
out = ''
while True:
if self.channel.recv_ready():
line = self._decode(self.channel.recv(8196))
out += line
out += self._decode(self.channel.recv(8196))
if self.regex.search(out):
self.stdout = self.channel.makefile('r')
break

View File

@ -102,6 +102,7 @@ TEMPLATES = [
},
]
TOKEN_TTL = 8 * 3600
SCHEDULE_KEY = 'spug:schedule'
SCHEDULE_WORKER_KEY = 'spug:schedule:worker'
MONITOR_KEY = 'spug:monitor'