Added captcha-check
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user