recaptcha.py
1 from typing import cast 2 3 import aiohttp 4 5 from api.settings import settings 6 7 8 def recaptcha_enabled() -> bool: 9 return bool(settings.recaptcha_secret and settings.recaptcha_sitekey) 10 11 12 async def check_recaptcha(response: str) -> bool: 13 async with aiohttp.ClientSession() as session: 14 async with session.post( 15 "https://www.google.com/recaptcha/api/siteverify", 16 data={"secret": settings.recaptcha_secret, "response": response}, 17 ) as resp: 18 return cast(bool, (await resp.json())["success"])