34 lines
937 B
Python
34 lines
937 B
Python
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')
|