Added captcha-check

This commit is contained in:
Mawoka
2022-02-28 15:07:27 +01:00
parent 208bc89a5e
commit 80218d92b1
2 changed files with 10 additions and 12 deletions
+1 -10
View File
@@ -10,24 +10,15 @@ class Settings(BaseSettings):
redis: RedisDsn = "redis://localhost:6379/0?decode_responses=True"
skip_email_verification: bool = False
db_url: str = "sqlite:///classquiz.db"
hcaptcha_key: str
mail_address: str
mail_password: str
mail_username: str
mail_server: str
mail_port: int
secret_key: str
minio_url: str = "127.0.0.1"
minio_access_key: str
minio_secret_key: str
minio_bucket: str
minio_secure: bool = True
access_token_expire_minutes: int = 30
cache_expiry: int = 86400
typesense_api_key: str
typesense_host: str = "localhost"
typesense_port: int = 8108
typesense_protocol: str = "http"
typesense_timeout: int = 2
class Config:
env_file = ".env"
+9 -2
View File
@@ -1,7 +1,8 @@
import socketio
import json
from classquiz.config import redis
from classquiz.config import redis, settings
from classquiz.db.models import GameSession, GameAnser1, GameAnser2, PlayGame
import aiohttp
from redis.commands.json.path import Path
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
@@ -22,7 +23,13 @@ async def connect(sid, environ, lol):
@sio.event
async def join_game(sid, data):
print(sid, data, "JOIN_GAME")
async with aiohttp.ClientSession() as session:
async with session.post("https://hcaptcha.com/siteverify",
data={"response": data["captcha"], "secret": settings.hcaptcha_key}) as resp:
resp_data = await resp.json()
if not resp_data["success"]:
print("CAPTCHA FAILED")
return
redis_res = await redis.get(f"game:{data['game_pin']}")
if redis_res is None:
await sio.emit("game_not_found", room=sid)