perf: 优化登录,cas, openid 自动登录

This commit is contained in:
ibuler
2021-04-29 17:15:46 +08:00
committed by 老广
parent 7294f6e5e0
commit 4d6d4cbc22
14 changed files with 217 additions and 153 deletions

View File

@@ -8,3 +8,4 @@ from .http import *
from .ipip import *
from .crypto import *
from .random import *
from .jumpserver import *

View File

@@ -0,0 +1,31 @@
from django.core.cache import cache
from django.shortcuts import reverse
from .random import random_string
__all__ = ['FlashMessageUtil']
class FlashMessageUtil:
@staticmethod
def get_key(code):
key = 'MESSAGE_{}'.format(code)
return key
@classmethod
def get_message_code(cls, message_data):
code = random_string(12)
key = cls.get_key(code)
cache.set(key, message_data, 60)
return code
@classmethod
def get_message_by_code(cls, code):
key = cls.get_key(code)
return cache.get(key)
@classmethod
def gen_message_url(cls, message_data):
code = cls.get_message_code(message_data)
return reverse('common:flash-message') + f'?code={code}'