mirror of https://github.com/openspug/spug
U 新增会话过期时间配置TOKEN_TTL
parent
9ba9f5782e
commit
833b49a822
|
@ -2,6 +2,7 @@
|
||||||
# Copyright: (c) <spug.dev@gmail.com>
|
# Copyright: (c) <spug.dev@gmail.com>
|
||||||
# Released under the AGPL-3.0 License.
|
# Released under the AGPL-3.0 License.
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.conf import settings
|
||||||
from libs.mixins import AdminView, View
|
from libs.mixins import AdminView, View
|
||||||
from libs import JsonParser, Argument, human_datetime, json_response
|
from libs import JsonParser, Argument, human_datetime, json_response
|
||||||
from libs.utils import get_request_real_ip, generate_random_str
|
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)
|
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()
|
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.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_login = human_datetime()
|
||||||
user.last_ip = x_real_ip
|
user.last_ip = x_real_ip
|
||||||
user.save()
|
user.save()
|
||||||
|
|
|
@ -155,11 +155,10 @@ class SSH:
|
||||||
command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n'
|
command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n'
|
||||||
command = self._handle_command(command, self.default_env)
|
command = self._handle_command(command, self.default_env)
|
||||||
self.channel.sendall(command)
|
self.channel.sendall(command)
|
||||||
out = line = ''
|
out = ''
|
||||||
while True:
|
while True:
|
||||||
if self.channel.recv_ready():
|
if self.channel.recv_ready():
|
||||||
line = self._decode(self.channel.recv(8196))
|
out += self._decode(self.channel.recv(8196))
|
||||||
out += line
|
|
||||||
if self.regex.search(out):
|
if self.regex.search(out):
|
||||||
self.stdout = self.channel.makefile('r')
|
self.stdout = self.channel.makefile('r')
|
||||||
break
|
break
|
||||||
|
|
|
@ -102,6 +102,7 @@ TEMPLATES = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
TOKEN_TTL = 8 * 3600
|
||||||
SCHEDULE_KEY = 'spug:schedule'
|
SCHEDULE_KEY = 'spug:schedule'
|
||||||
SCHEDULE_WORKER_KEY = 'spug:schedule:worker'
|
SCHEDULE_WORKER_KEY = 'spug:schedule:worker'
|
||||||
MONITOR_KEY = 'spug:monitor'
|
MONITOR_KEY = 'spug:monitor'
|
||||||
|
|
Loading…
Reference in New Issue