Added captcha-check
This commit is contained in:
+1
-10
@@ -10,24 +10,15 @@ class Settings(BaseSettings):
|
|||||||
redis: RedisDsn = "redis://localhost:6379/0?decode_responses=True"
|
redis: RedisDsn = "redis://localhost:6379/0?decode_responses=True"
|
||||||
skip_email_verification: bool = False
|
skip_email_verification: bool = False
|
||||||
db_url: str = "sqlite:///classquiz.db"
|
db_url: str = "sqlite:///classquiz.db"
|
||||||
|
hcaptcha_key: str
|
||||||
mail_address: str
|
mail_address: str
|
||||||
mail_password: str
|
mail_password: str
|
||||||
mail_username: str
|
mail_username: str
|
||||||
mail_server: str
|
mail_server: str
|
||||||
mail_port: int
|
mail_port: int
|
||||||
secret_key: str
|
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
|
access_token_expire_minutes: int = 30
|
||||||
cache_expiry: int = 86400
|
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:
|
class Config:
|
||||||
env_file = ".env"
|
env_file = ".env"
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import socketio
|
import socketio
|
||||||
import json
|
import json
|
||||||
from classquiz.config import redis
|
from classquiz.config import redis, settings
|
||||||
from classquiz.db.models import GameSession, GameAnser1, GameAnser2, PlayGame
|
from classquiz.db.models import GameSession, GameAnser1, GameAnser2, PlayGame
|
||||||
|
import aiohttp
|
||||||
from redis.commands.json.path import Path
|
from redis.commands.json.path import Path
|
||||||
|
|
||||||
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
|
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
|
||||||
@@ -22,7 +23,13 @@ async def connect(sid, environ, lol):
|
|||||||
|
|
||||||
@sio.event
|
@sio.event
|
||||||
async def join_game(sid, data):
|
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']}")
|
redis_res = await redis.get(f"game:{data['game_pin']}")
|
||||||
if redis_res is None:
|
if redis_res is None:
|
||||||
await sio.emit("game_not_found", room=sid)
|
await sio.emit("game_not_found", room=sid)
|
||||||
|
|||||||
Reference in New Issue
Block a user