openreplay/api/chalicelib/utils/captcha.py
Amirouche 66040ea9f5 wip
2024-02-06 14:18:50 +01:00

29 lines
771 B
Python

import logging
import httpx
from decouple import config
from chalicelib.utils import helper
logger = logging.getLogger(__name__)
def __get_captcha_config():
return config("captcha_server"), config("captcha_key")
async def is_valid(response):
if not helper.allow_captcha():
logger.info("!! Captcha is disabled")
return True
url, secret = __get_captcha_config()
async with httpx.AsyncClient() as client:
r = await client.post(url=url, data={"secret": secret, "response": response})
if r.status_code != 200:
logger.warning("something went wrong")
logger.error(r)
logger.warning(r.status_code)
logger.warning(r.text)
return
r = r.json()
logger.debug(r)
return r["success"]