加入了 GVSDSDK 模块,进行了 QModel 兼容层的尝试,生产环境可用
This commit is contained in:
33
gvsdsdk/auth/cookie.py
Normal file
33
gvsdsdk/auth/cookie.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
|
||||
ELT_COOKIE_NAME = getattr(settings, 'ELT_COOKIE_NAME', 'ELToken')
|
||||
ELT_COOKIE_DOMAIN = getattr(settings, 'ELT_COOKIE_DOMAIN', '.gvsds.com')
|
||||
ELT_COOKIE_MAX_AGE = getattr(settings, 'ELT_COOKIE_MAX_AGE', 30 * 24 * 60 * 60)
|
||||
|
||||
|
||||
def SetELTCookie(response, token_str):
|
||||
response.set_cookie(
|
||||
ELT_COOKIE_NAME, token_str,
|
||||
domain=ELT_COOKIE_DOMAIN,
|
||||
max_age=ELT_COOKIE_MAX_AGE,
|
||||
secure=True, httponly=True, samesite='None',
|
||||
)
|
||||
|
||||
|
||||
def DeleteELTCookie(response):
|
||||
response.delete_cookie(
|
||||
ELT_COOKIE_NAME,
|
||||
domain=ELT_COOKIE_DOMAIN,
|
||||
samesite='None',
|
||||
)
|
||||
|
||||
|
||||
def GetDefaultAvatar():
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
img = Image.new('RGB', (256, 256), (200, 200, 200))
|
||||
buf = BytesIO()
|
||||
img.save(buf, format='PNG')
|
||||
buf.seek(0)
|
||||
return HttpResponse(buf.read(), content_type='image/png')
|
||||
Reference in New Issue
Block a user