2021-04-13 22:09:33 +09:00
|
|
|
import base64
|
|
|
|
import io
|
|
|
|
import secrets
|
|
|
|
from captcha.image import ImageCaptcha
|
|
|
|
from website.constants import CONFIG, BACKGROUND_COLOUR
|
|
|
|
|
|
|
|
CAPTCHA_CHARSET = '346qwertypagkxvbm'
|
|
|
|
CAPTCHA_LENGTH = 3
|
|
|
|
CAPTCHA = ImageCaptcha(width=72, height=30, fonts=CONFIG['fonts'], font_sizes=(24, 27, 30))
|
|
|
|
|
|
|
|
def _image_to_base64(im):
|
|
|
|
buffer = io.BytesIO()
|
|
|
|
im.save(buffer, format='jpeg', quality=70)
|
|
|
|
buffer.seek(0)
|
|
|
|
b64 = base64.b64encode(buffer.read()).rstrip(b'=')
|
|
|
|
return (b'data:image/jpeg;base64,' + b64).decode()
|
|
|
|
|
|
|
|
def gen_captcha():
|
|
|
|
answer = ''.join(secrets.choice(CAPTCHA_CHARSET) for _ in range(CAPTCHA_LENGTH))
|
|
|
|
im = CAPTCHA.create_captcha_image(answer, (0xff, 0xff, 0xff), tuple(BACKGROUND_COLOUR))
|
Update website/static/external/grids-responsive-min.css, website/static/external/pure-min.css, website/static/external/video-js.css, website/static/external/video.js, website/static/external/videojs-contrib-hls.js, website/static/platform.css, website/static/platform.js, website/templates/chat-iframe.html, website/templates/comment-iframe.html, website/templates/index.html, website/templates/stream-info-iframe.html, website/utils/captcha.py, website/utils/colour.py, website/utils/stream.py, website/utils/tripcode.py, website/chat.py, website/concatenate.py, website/routes.py, website/viewership.py files
2021-04-14 23:12:40 +09:00
|
|
|
return _image_to_base64(im), answer
|