0Mart00 commited on
Commit ·
76d8f10
1
Parent(s): 2f2bdfe
Refactor: public/private split, route fixes, docker ARG support
Browse files- Dockerfile +23 -8
- docker-compose.yml +34 -4
- src/wordgame/api/__init__.py +0 -4
- src/wordgame/api/router.py +0 -74
- src/wordgame/api/routes/game_routes.py +0 -1308
- src/wordgame/api/routes/paddle_routes.py +0 -37
- src/wordgame/app_factory.py +152 -0
- src/wordgame/core/auth.py +171 -0
- src/wordgame/core/config.py +89 -18
- src/wordgame/main.py +0 -91
- src/wordgame/main_private.py +20 -0
- src/wordgame/main_public.py +20 -0
- src/wordgame/private/__init__.py +7 -0
- src/wordgame/{api → private}/routes/__init__.py +10 -10
- src/wordgame/{api → private}/routes/admin_routes.py +72 -68
- src/wordgame/{api → private}/routes/dashboard_routes.py +236 -161
- src/wordgame/private/routes/paddle_routes.py +127 -0
- src/wordgame/{api → private}/routes/room_routes.py +90 -71
- src/wordgame/{api → private}/routes/slang_routes.py +10 -14
- src/wordgame/private/routes/sso_callback.py +74 -0
- src/wordgame/public/__init__.py +7 -0
- src/wordgame/public/routes/__init__.py +4 -0
- src/wordgame/{api → public}/routes/auth_routes.py +45 -49
- src/wordgame/public/routes/game_routes.py +378 -0
- src/wordgame/shared/__init__.py +5 -0
- src/wordgame/shared/routes/__init__.py +4 -0
- src/wordgame/shared/routes/health_routes.py +37 -0
- src/wordgame/templates/dashboard.html +66 -0
Dockerfile
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
# WordGame Docker Image
|
|
|
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
# Set working directory
|
|
@@ -9,6 +10,13 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
gcc \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Copy requirements first for better caching
|
| 13 |
COPY requirements.txt .
|
| 14 |
|
|
@@ -18,13 +26,20 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 18 |
# Copy the rest of the application
|
| 19 |
COPY . .
|
| 20 |
|
| 21 |
-
# Expose port
|
| 22 |
-
EXPOSE
|
| 23 |
|
| 24 |
-
# Set environment variables
|
| 25 |
ENV PYTHONPATH=/app
|
| 26 |
ENV HOST=0.0.0.0
|
| 27 |
-
ENV PORT=
|
| 28 |
-
|
| 29 |
-
#
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# WordGame / Lingo Docker Image (univerzális, mindkét HF Space-re)
|
| 2 |
+
# A HF Space Variables-ben beállított APP_MODE build arg-ként is átadódik.
|
| 3 |
FROM python:3.11-slim
|
| 4 |
|
| 5 |
# Set working directory
|
|
|
|
| 10 |
gcc \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# ------------------------------------------------
|
| 14 |
+
# Build argument – a HF Space Variables-ből jön
|
| 15 |
+
# Értéke: "public" (WordGame) vagy "private" (Lingo)
|
| 16 |
+
# ------------------------------------------------
|
| 17 |
+
ARG APP_MODE=public
|
| 18 |
+
ENV APP_MODE=${APP_MODE}
|
| 19 |
+
|
| 20 |
# Copy requirements first for better caching
|
| 21 |
COPY requirements.txt .
|
| 22 |
|
|
|
|
| 26 |
# Copy the rest of the application
|
| 27 |
COPY . .
|
| 28 |
|
| 29 |
+
# Expose port (HF Spaces alapértelmezett: 7860)
|
| 30 |
+
EXPOSE 7860
|
| 31 |
|
| 32 |
+
# Set runtime environment variables
|
| 33 |
ENV PYTHONPATH=/app
|
| 34 |
ENV HOST=0.0.0.0
|
| 35 |
+
ENV PORT=7860
|
| 36 |
+
|
| 37 |
+
# A HF Space-ek a 7860-as portot várják.
|
| 38 |
+
# Az APP_MODE alapján indul a public vagy a private entry point.
|
| 39 |
+
CMD if [ "$APP_MODE" = "private" ]; then \
|
| 40 |
+
echo "🔒 Indítás: PRIVATE (Lingo) módban"; \
|
| 41 |
+
uvicorn src.wordgame.main_private:app --host 0.0.0.0 --port 7860; \
|
| 42 |
+
else \
|
| 43 |
+
echo "🌍 Indítás: PUBLIC (WordGame) módban"; \
|
| 44 |
+
uvicorn src.wordgame.main_public:app --host 0.0.0.0 --port 7860; \
|
| 45 |
+
fi
|
docker-compose.yml
CHANGED
|
@@ -1,17 +1,47 @@
|
|
| 1 |
version: '3.8'
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
services:
|
|
|
|
| 4 |
wordgame:
|
| 5 |
build:
|
| 6 |
context: .
|
| 7 |
dockerfile: Dockerfile
|
|
|
|
|
|
|
|
|
|
| 8 |
ports:
|
| 9 |
-
- "8030:
|
|
|
|
|
|
|
| 10 |
environment:
|
| 11 |
-
-
|
| 12 |
-
- SUPABASE_KEY=${SUPABASE_KEY:-}
|
| 13 |
volumes:
|
| 14 |
- .:/app
|
| 15 |
- /app/__pycache__
|
| 16 |
restart: unless-stopped
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
version: '3.8'
|
| 2 |
|
| 3 |
+
# Két service ugyanabból a Dockerfile-ból – a különbség az APP_MODE
|
| 4 |
+
# build argumentumban van. Így egy gépen egyszerre is futtatható
|
| 5 |
+
# a public (WordGame) és a private (Lingo) Space fejlesztés közben.
|
| 6 |
+
#
|
| 7 |
+
# HF Space-eken: mindkét Space ugyanazt a Dockerfile-t használja,
|
| 8 |
+
# csak a Space Variables-ben beállított APP_MODE különbözik.
|
| 9 |
+
|
| 10 |
services:
|
| 11 |
+
# --- Public: WordGame Space (játék, login, ranglétra) ---
|
| 12 |
wordgame:
|
| 13 |
build:
|
| 14 |
context: .
|
| 15 |
dockerfile: Dockerfile
|
| 16 |
+
args:
|
| 17 |
+
APP_MODE: public
|
| 18 |
+
container_name: wordgame-public
|
| 19 |
ports:
|
| 20 |
+
- "8030:7860"
|
| 21 |
+
env_file:
|
| 22 |
+
- .env
|
| 23 |
environment:
|
| 24 |
+
- APP_MODE=public
|
|
|
|
| 25 |
volumes:
|
| 26 |
- .:/app
|
| 27 |
- /app/__pycache__
|
| 28 |
restart: unless-stopped
|
| 29 |
+
|
| 30 |
+
# --- Private: Lingo Space (dashboard, szobák, admin, paddle) ---
|
| 31 |
+
lingo:
|
| 32 |
+
build:
|
| 33 |
+
context: .
|
| 34 |
+
dockerfile: Dockerfile
|
| 35 |
+
args:
|
| 36 |
+
APP_MODE: private
|
| 37 |
+
container_name: wordgame-private
|
| 38 |
+
ports:
|
| 39 |
+
- "8031:7860"
|
| 40 |
+
env_file:
|
| 41 |
+
- .env
|
| 42 |
+
environment:
|
| 43 |
+
- APP_MODE=private
|
| 44 |
+
volumes:
|
| 45 |
+
- .:/app
|
| 46 |
+
- /app/__pycache__
|
| 47 |
+
restart: unless-stopped
|
src/wordgame/api/__init__.py
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
"""API module - Route definitions and request handling."""
|
| 2 |
-
from .router import create_router
|
| 3 |
-
|
| 4 |
-
__all__ = ["create_router"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/wordgame/api/router.py
DELETED
|
@@ -1,74 +0,0 @@
|
|
| 1 |
-
"""Main application router - aggregates all route modules."""
|
| 2 |
-
from fastapi import APIRouter
|
| 3 |
-
from starlette.templating import Jinja2Templates
|
| 4 |
-
from fastapi.responses import HTMLResponse
|
| 5 |
-
from ..core.config import settings
|
| 6 |
-
from .routes import (
|
| 7 |
-
game_routes,
|
| 8 |
-
auth_routes,
|
| 9 |
-
room_routes,
|
| 10 |
-
slang_routes,
|
| 11 |
-
paddle_routes,
|
| 12 |
-
dashboard_routes,
|
| 13 |
-
admin_routes
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 18 |
-
"""Create and configure the main application router.
|
| 19 |
-
|
| 20 |
-
Args:
|
| 21 |
-
templates: Jinja2 templates instance for rendering HTML
|
| 22 |
-
|
| 23 |
-
Returns:
|
| 24 |
-
Configured APIRouter with all routes registered
|
| 25 |
-
"""
|
| 26 |
-
router = APIRouter()
|
| 27 |
-
|
| 28 |
-
# Game routes (main game logic, leaderboard, premium)
|
| 29 |
-
router.include_router(
|
| 30 |
-
game_routes.create_router(templates),
|
| 31 |
-
tags=["game"]
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# Authentication routes (login, register, password reset)
|
| 35 |
-
router.include_router(
|
| 36 |
-
auth_routes.create_router(templates),
|
| 37 |
-
prefix="/auth",
|
| 38 |
-
tags=["auth"]
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
# Room routes (multiplayer room management)
|
| 42 |
-
router.include_router(
|
| 43 |
-
room_routes.create_router(),
|
| 44 |
-
prefix="/szoba",
|
| 45 |
-
tags=["rooms"]
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
# Slang word import routes
|
| 49 |
-
router.include_router(
|
| 50 |
-
slang_routes.create_router(),
|
| 51 |
-
prefix="/szoba/import",
|
| 52 |
-
tags=["slang"]
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
# Paddle payment webhook
|
| 56 |
-
router.include_router(
|
| 57 |
-
paddle_routes.create_router(),
|
| 58 |
-
tags=["payments"]
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
# User dashboard routes
|
| 62 |
-
router.include_router(
|
| 63 |
-
dashboard_routes.create_router(templates),
|
| 64 |
-
prefix="/dashboard",
|
| 65 |
-
tags=["dashboard"]
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
# Admin routes (hidden URL)
|
| 69 |
-
router.include_router(
|
| 70 |
-
admin_routes.create_router(templates),
|
| 71 |
-
tags=["admin"]
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
return router
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/wordgame/api/routes/game_routes.py
DELETED
|
@@ -1,1308 +0,0 @@
|
|
| 1 |
-
"""Game routes - main game logic, leaderboard, premium page."""
|
| 2 |
-
import hashlib
|
| 3 |
-
import os
|
| 4 |
-
from datetime import date
|
| 5 |
-
from collections import Counter
|
| 6 |
-
from fastapi import APIRouter, Request, Cookie
|
| 7 |
-
from fastapi.responses import HTMLResponse
|
| 8 |
-
from starlette.templating import Jinja2Templates
|
| 9 |
-
from ...core.database import supabase
|
| 10 |
-
from ...core.config import settings
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 14 |
-
"""Create game routes router.
|
| 15 |
-
|
| 16 |
-
Args:
|
| 17 |
-
templates: Jinja2 templates instance
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
Configured APIRouter
|
| 21 |
-
"""
|
| 22 |
-
router = APIRouter()
|
| 23 |
-
|
| 24 |
-
KATEGORIA_NEVEK = {
|
| 25 |
-
"szleng": "🔥 MAI SZLENG",
|
| 26 |
-
"matek": "🔢 MATEK MOD",
|
| 27 |
-
"gamer": "🎮 GAMER SPEC"
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
# Language-specific keyboard layouts
|
| 31 |
-
NYELV_BILLENTYUZET = {
|
| 32 |
-
"en": [
|
| 33 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 34 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 35 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 36 |
-
],
|
| 37 |
-
"hu": [
|
| 38 |
-
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ő", "Ú"],
|
| 39 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "É", "Á", "Ó"],
|
| 40 |
-
["Y", "X", "C", "V", "B", "N", "M", "Ö", "Ü", "Ű", "Í"]
|
| 41 |
-
],
|
| 42 |
-
"de": [
|
| 43 |
-
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ü"],
|
| 44 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ö", "Ä"],
|
| 45 |
-
["Y", "X", "C", "V", "B", "N", "M", "ß"]
|
| 46 |
-
],
|
| 47 |
-
"fr": [
|
| 48 |
-
["A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 49 |
-
["Q", "S", "D", "F", "G", "H", "J", "K", "L", "M"],
|
| 50 |
-
["W", "X", "C", "V", "B", "N", "À", "Ç", "É", "È"]
|
| 51 |
-
],
|
| 52 |
-
"es": [
|
| 53 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 54 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ñ"],
|
| 55 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 56 |
-
],
|
| 57 |
-
"it": [
|
| 58 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "È", "É"],
|
| 59 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "À", "Ù"],
|
| 60 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 61 |
-
],
|
| 62 |
-
"pt": [
|
| 63 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 64 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ç", "Ã", "Õ"],
|
| 65 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 66 |
-
],
|
| 67 |
-
"pl": [
|
| 68 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 69 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ą", "Ó"],
|
| 70 |
-
["Z", "X", "C", "V", "B", "N", "M", "Ś", "Ż", "Ź", "Ć", "Ń", "Ł"]
|
| 71 |
-
],
|
| 72 |
-
"nl": [
|
| 73 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 74 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 75 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 76 |
-
],
|
| 77 |
-
"sv": [
|
| 78 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Å"],
|
| 79 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ä", "Ö"],
|
| 80 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 81 |
-
],
|
| 82 |
-
"fi": [
|
| 83 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Å"],
|
| 84 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ä", "Ö"],
|
| 85 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 86 |
-
],
|
| 87 |
-
"da": [
|
| 88 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Å"],
|
| 89 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Æ", "Ø"],
|
| 90 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 91 |
-
],
|
| 92 |
-
"no": [
|
| 93 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Å"],
|
| 94 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Æ", "Ø"],
|
| 95 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 96 |
-
],
|
| 97 |
-
"cs": [
|
| 98 |
-
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ú"],
|
| 99 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Š", "Č", "Ř", "Ž", "Ý", "Á", "Í", "É"],
|
| 100 |
-
["Y", "X", "C", "V", "B", "N", "M", "Ď", "Ť", "Ň", "Ě"]
|
| 101 |
-
],
|
| 102 |
-
"sk": [
|
| 103 |
-
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ú"],
|
| 104 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Š", "Č", "Ž", "Ý", "Á", "Í", "É"],
|
| 105 |
-
["Y", "X", "C", "V", "B", "N", "M", "Ď", "Ť", "Ň", "Ô"]
|
| 106 |
-
],
|
| 107 |
-
"ro": [
|
| 108 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ă", "Î"],
|
| 109 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ș", "Ț", "Â"],
|
| 110 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 111 |
-
],
|
| 112 |
-
"hr": [
|
| 113 |
-
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Š", "Đ", "Č"],
|
| 114 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ž", "Ć"],
|
| 115 |
-
["Y", "X", "C", "V", "B", "N", "M"]
|
| 116 |
-
],
|
| 117 |
-
"sl": [
|
| 118 |
-
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Š", "Đ", "Č"],
|
| 119 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ž", "Ć"],
|
| 120 |
-
["Y", "X", "C", "V", "B", "N", "M"]
|
| 121 |
-
],
|
| 122 |
-
"et": [
|
| 123 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ü", "Õ"],
|
| 124 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ä", "Ö"],
|
| 125 |
-
["Z", "X", "C", "V", "B", "N", "M", "Š", "Ž"]
|
| 126 |
-
],
|
| 127 |
-
"lv": [
|
| 128 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ū"],
|
| 129 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ā", "Ī"],
|
| 130 |
-
["Z", "X", "C", "V", "B", "N", "M", "Č", "Š", "Ž", "Ē", "Ģ", "Ķ", "Ļ", "Ņ"]
|
| 131 |
-
],
|
| 132 |
-
"lt": [
|
| 133 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 134 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ą", "Č", "Ė", "Į", "Š", "Ų", "Ū", "Ž"],
|
| 135 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 136 |
-
],
|
| 137 |
-
"el": [
|
| 138 |
-
[";", "ς", "Ε", "Ρ", "Τ", "Υ", "Θ", "Ι", "Ο", "Π"],
|
| 139 |
-
["Α", "Σ", "Δ", "Φ", "Γ", "Η", "Ξ", "Κ", "Λ"],
|
| 140 |
-
["Ζ", "Χ", "Ψ", "Ω", "Β", "Ν", "Μ", "Ά", "Έ", "Ή", "Ί", "Ό", "Ύ", "Ώ"]
|
| 141 |
-
],
|
| 142 |
-
"ru": [
|
| 143 |
-
["Й", "Ц", "У", "К", "Е", "Н", "Г", "Ш", "Щ", "З", "Х", "Ъ"],
|
| 144 |
-
["Ф", "Ы", "В", "А", "П", "Р", "О", "Л", "Д", "Ж", "Э"],
|
| 145 |
-
["Я", "Ч", "С", "М", "И", "Т", "Ь", "Б", "Ю", "Ё"]
|
| 146 |
-
],
|
| 147 |
-
"bg": [
|
| 148 |
-
["Я", "В", "Е", "Р", "Т", "Ъ", "У", "И", "О", "П", "Ш", "Щ", "Ю"],
|
| 149 |
-
["А", "С", "Д", "Ф", "Г", "Х", "Й", "К", "Л", "Ж", "З", "Ц"],
|
| 150 |
-
["З", "Ь", "Ч", "Н", "Б", "М", "ДЖ", "ДЗ", "А", "Ю"]
|
| 151 |
-
],
|
| 152 |
-
# Additional keyboard layouts for more languages
|
| 153 |
-
"ja": [
|
| 154 |
-
["あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ"],
|
| 155 |
-
["さ", "し", "す", "せ", "そ", "た", "ち", "つ", "て", "と"],
|
| 156 |
-
["な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ", "ま", "み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "を", "ん"]
|
| 157 |
-
],
|
| 158 |
-
"zh": [
|
| 159 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 160 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 161 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 162 |
-
],
|
| 163 |
-
"ko": [
|
| 164 |
-
["ㄱ", "ㄴ", "ㄷ", "ㄹ", "ㅁ", "ㅂ", "ㅅ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"],
|
| 165 |
-
["ㅏ", "ㅑ", "ㅓ", "ㅕ", "ㅗ", "ㅛ", "ㅜ", "ㅠ", "ㅡ", "ㅣ", "ㅐ", "ㅔ", "ㅚ", "ㅟ"],
|
| 166 |
-
["가", "나", "다", "라", "마", "바", "사", "아", "자", "차", "카", "타", "파", "하"]
|
| 167 |
-
],
|
| 168 |
-
"ar": [
|
| 169 |
-
["ض", "ص", "ث", "ق", "ف", "غ", "ع", "ه", "خ", "ح", "ج", "د"],
|
| 170 |
-
["ش", "س", "ي", "ب", "ل", "ا", "ت", "ن", "م", "ك", "ط"],
|
| 171 |
-
["ئ", "ء", "ؤ", "ر", "لا", "ى", "ة", "و", "ز", "ظ", "ذ"]
|
| 172 |
-
],
|
| 173 |
-
"he": [
|
| 174 |
-
["ק", "ר", "א", "ט", "ו", "ם", "ן", "י", "ח", "ל", "ך", "ף"],
|
| 175 |
-
["ש", "ד", "ג", "כ", "ע", "י", "ח", "ל", "ך", "ף"],
|
| 176 |
-
["ז", "ס", "ב", "ה", "נ", "מ", "צ", "ת", "ץ"]
|
| 177 |
-
],
|
| 178 |
-
"hi": [
|
| 179 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 180 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 181 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह"]
|
| 182 |
-
],
|
| 183 |
-
"tr": [
|
| 184 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ğ", "Ü"],
|
| 185 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ş", "İ"],
|
| 186 |
-
["Z", "X", "C", "V", "B", "N", "M", "Ö", "Ç"]
|
| 187 |
-
],
|
| 188 |
-
"th": [
|
| 189 |
-
["ๅ", "/", "_", "-", "ภ", "ถ", "ุ", "ึ", "ค", "ต", "จ", "ข", "ช"],
|
| 190 |
-
["ๆ", "ไ", "ำ", "พ", "ะ", "ั", "ี", "ร", "น", "ย", "บ", "ล", "ฃ"],
|
| 191 |
-
["ฟ", "ห", "ก", "ด", "เ", "้", "่", "า", "ส", "ว", "ง", "ผ", "ป", "แ", "อ", "ิ", "ื", "ท", "ม", "ใ", "ฝ"]
|
| 192 |
-
],
|
| 193 |
-
"vi": [
|
| 194 |
-
["Ă", "Ê", "Ô", "Ơ", "Ư", "Đ", "A", "Ă", "Â", "E", "Ê", "O", "Ô", "Ơ"],
|
| 195 |
-
["I", "A", "Ă", "Â", "E", "Ê", "O", "Ô", "Ơ", "U", "Ư", "Y"],
|
| 196 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"]
|
| 197 |
-
],
|
| 198 |
-
"fa": [
|
| 199 |
-
["پ", "چ", "ژ", "ش", "غ", "ظ", "ک", "گ", "ی"],
|
| 200 |
-
["س", "ق", "و", "ه", "ت", "ن", "م", "ک", "گ"],
|
| 201 |
-
["ز", "خ", "ح", "ج", "د", "ر", "ب", "ا", "ل", "ف", "ع", "ط", "ص", "ث"]
|
| 202 |
-
],
|
| 203 |
-
"ur": [
|
| 204 |
-
["آ", "ا", "ب", "پ", "ت", "ٹ", "ث", "ج", "چ", "ح", "خ"],
|
| 205 |
-
["د", "ڈ", "ذ", "ر", "ڑ", "ز", "ژ", "س", "ش", "ص", "ض"],
|
| 206 |
-
["ط", "ظ", "ع", "غ", "ف", "ق", "ک", "گ", "ل", "م", "ن", "و", "ہ", "ی", "ے"]
|
| 207 |
-
],
|
| 208 |
-
"bn": [
|
| 209 |
-
["অ", "আ", "ই", "ঈ", "উ", "ঊ", "ঋ", "এ", "ঐ", "ও", "ঔ"],
|
| 210 |
-
["ক", "খ", "গ", "ঘ", "ঙ", "চ", "ছ", "জ", "ঝ", "ঞ"],
|
| 211 |
-
["ট", "ঠ", "ড", "ঢ", "ণ", "ত", "থ", "দ", "ধ", "ন", "প", "ফ", "ব", "ভ", "ম", "য", "র", "ল", "শ", "ষ", "স", "হ", "ড়", "ঢ়", "য়", "ক্ষ", "জ্ঞ"]
|
| 212 |
-
],
|
| 213 |
-
"ta": [
|
| 214 |
-
["அ", "ஆ", "இ", "ஈ", "உ", "ஊ", "எ", "ஏ", "ஐ", "ஒ", "ஓ", "ஔ"],
|
| 215 |
-
["க", "ங", "ச", "ஞ", "ட", "ண", "த", "ந", "ப", "ம", "ய", "ர", "ல", "வ", "ழ", "ள", "ற", "ன"],
|
| 216 |
-
["ஷ", "ஸ", "ஹ", "க்ஷ"]
|
| 217 |
-
],
|
| 218 |
-
"te": [
|
| 219 |
-
["అ", "ఆ", "ఇ", "ఈ", "ఉ", "ఊ", "ఋ", "ఎ", "ఏ", "ఐ", "ఒ", "ఓ", "ఔ"],
|
| 220 |
-
["క", "ఖ", "గ", "ఘ", "ఙ", "చ", "ఛ", "జ", "ఝ", "ఞ"],
|
| 221 |
-
["ట", "ఠ", "డ", "ఢ", "ణ", "త", "థ", "ద", "ధ", "న", "ప", "ఫ", "బ", "భ", "మ", "య", "ర", "ల", "వ", "శ", "ష", "స", "హ", "ళ", "క్ష", "జ్ఞ"]
|
| 222 |
-
],
|
| 223 |
-
"kn": [
|
| 224 |
-
["ಅ", "ಆ", "ಇ", "ಈ", "ಉ", "ಊ", "ಋ", "ಎ", "ಏ", "ಐ", "ಒ", "ಓ", "ಔ"],
|
| 225 |
-
["ಕ", "ಖ", "ಗ", "ಘ", "ಙ", "ಚ", "ಛ", "ಜ", "ಝ", "ಞ"],
|
| 226 |
-
["ಟ", "ಠ", "ಡ", "ಢ", "ಣ", "ತ", "ಥ", "ದ", "ಧ", "ನ", "ಪ", "ಫ", "ಬ", "ಭ", "ಮ", "ಯ", "ರ", "ಲ", "ವ", "ಶ", "ಷ", "ಸ", "ಹ", "ಳ", "ಕ್ಷ", "ಜ್ಞ"]
|
| 227 |
-
],
|
| 228 |
-
"ml": [
|
| 229 |
-
["അ", "ആ", "ഇ", "ഈ", "ഉ", "ഊ", "ഋ", "എ", "ഏ", "ഐ", "ഒ", "ഓ", "ഔ"],
|
| 230 |
-
["ക", "ഖ", "ഗ", "ഘ", "ങ", "ച", "ഛ", "ജ", "ഝ", "ഞ"],
|
| 231 |
-
["ട", "ഠ", "ഡ", "ഢ", "ണ", "ത", "ഥ", "ദ", "ധ", "ന", "പ", "ഫ", "ബ", "ഭ", "മ", "യ", "ര", "ല", "വ", "ശ", "ഷ", "സ", "ഹ", "ള", "ഴ", "റ", "ക്ഷ", "ജ്ഞ"]
|
| 232 |
-
],
|
| 233 |
-
"gu": [
|
| 234 |
-
["અ", "આ", "ઇ", "ઈ", "ઉ", "ઊ", "ઋ", "એ", "ઐ", "ઓ", "ઔ"],
|
| 235 |
-
["ક", "ખ", "ગ", "ઘ", "ઙ", "ચ", "છ", "જ", "ઝ", "ઞ"],
|
| 236 |
-
["ટ", "ઠ", "ડ", "ઢ", "ણ", "ત", "થ", "દ", "ધ", "ન", "પ", "ફ", "બ", "ભ", "મ", "ય", "ર", "લ", "વ", "શ", "ષ", "સ", "હ", "ળ", "ક્ષ", "જ્ઞ"]
|
| 237 |
-
],
|
| 238 |
-
"pa": [
|
| 239 |
-
["ਅ", "ਆ", "ਇ", "ਈ", "ਉ", "ਊ", "ਏ", "ਐ", "ਓ", "ਔ"],
|
| 240 |
-
["ਕ", "ਖ", "ਗ", "ਘ", "ਚ", "ਛ", "ਜ", "ਝ", "ਟ", "ਠ"],
|
| 241 |
-
["ਡ", "ਢ", "ਣ", "ਤ", "ਥ", "ਦ", "ਧ", "ਨ", "ਪ", "ਫ", "ਬ", "ਭ", "ਮ", "ਯ", "ਰ", "ਲ", "ਵ", "ਸ", "ਹ", "ਸ਼", "ਖ਼", "ਗ਼", "ਜ਼", "ਫ਼", "ਲ਼", "ਨ਼"]
|
| 242 |
-
],
|
| 243 |
-
"mr": [
|
| 244 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 245 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 246 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह", "ळ", "क्ष", "ज्ञ"]
|
| 247 |
-
],
|
| 248 |
-
"ne": [
|
| 249 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 250 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 251 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह", "त्र", "क्ष", "ज्ञ"]
|
| 252 |
-
],
|
| 253 |
-
"si": [
|
| 254 |
-
["අ", "ආ", "ඇ", "ඈ", "ඉ", "ඊ", "උ", "ඌ", "ඍ", "ඎ", "ඏ", "ඐ", "එ", "ඒ", "ඓ", "ඔ", "ඕ", "ඖ"],
|
| 255 |
-
["ක", "ඛ", "ග", "ඝ", "ඞ", "ච", "ඡ", "ජ", "ඣ", "ඤ"],
|
| 256 |
-
["ට", "ඨ", "ඩ", "ඪ", "ණ", "ත", "ථ", "ද", "ධ", "න", "ප", "ඵ", "බ", "භ", "ම", "ය", "ර", "ල", "ව", "ශ", "ෂ", "ස", "හ", "ළ", "ෆ"]
|
| 257 |
-
],
|
| 258 |
-
"my": [
|
| 259 |
-
["က", "ခ", "ဂ", "ဃ", "င", "စ", "ဆ", "ဇ", "ဈ", "ဉ", "ည"],
|
| 260 |
-
["ဋ", "ဌ", "ဍ", "ဎ", "ဏ", "တ", "ထ", "ဒ", "ဓ", "န", "ပ", "ဖ", "ဗ", "ဘ", "မ"],
|
| 261 |
-
["ယ", "ရ", "လ", "ဝ", "သ", "ဟ", "ဠ", "အ", "ဢ"]
|
| 262 |
-
],
|
| 263 |
-
"km": [
|
| 264 |
-
["ក", "ខ", "គ", "ឃ", "ង", "ច", "ឆ", "ជ", "ឈ", "ញ"],
|
| 265 |
-
["ដ", "ឋ", "ឌ", "ឍ", "ណ", "ត", "ថ", "ទ", "ធ", "ន"],
|
| 266 |
-
["ប", "ផ", "ព", "ភ", "ម", "យ", "រ", "ល", "វ", "ស", "ហ", "ឡ", "អ"]
|
| 267 |
-
],
|
| 268 |
-
"lo": [
|
| 269 |
-
["ກ", "ຂ", "ຄ", "ງ", "ຈ", "ສ", "ຊ", "ຍ", "ດ", "ຕ", "ຖ", "ທ", "ນ"],
|
| 270 |
-
["ບ", "ປ", "ຜ", "ຝ", "ພ", "ຟ", "ມ", "ຢ", "ຣ", "ລ", "ວ"],
|
| 271 |
-
["ສ", "ຫ", "ຮ", "ຯ", "ະ", "າ", "ຳ", "ິ", "ີ", "ຶ", "ື", "ຸ", "ູ"]
|
| 272 |
-
],
|
| 273 |
-
"ka": [
|
| 274 |
-
["ა", "ბ", "გ", "���", "ე", "ვ", "ზ", "თ", "ი", "კ", "ლ"],
|
| 275 |
-
["მ", "ნ", "ო", "პ", "ჟ", "რ", "ს", "ტ", "უ", "ფ", "ქ"],
|
| 276 |
-
["ღ", "ყ", "შ", "ჩ", "ც", "ძ", "წ", "ჭ", "ხ", "ჯ", "ჰ"]
|
| 277 |
-
],
|
| 278 |
-
"hy": [
|
| 279 |
-
["Ա", "Բ", "Գ", "Դ", "Ե", "Զ", "Է", "Ը", "Թ", "Ժ", "Ի"],
|
| 280 |
-
["Լ", "Խ", "Ծ", "Կ", "Հ", "Ձ", "Ղ", "Ճ", "Մ", "Յ", "Ն"],
|
| 281 |
-
["Շ", "Ո", "Չ", "Պ", "Ջ", "Ռ", "Ս", "Վ", "Տ", "Ր", "Ց", "Ւ", "Փ", "Ք", "Օ", "Ֆ"]
|
| 282 |
-
],
|
| 283 |
-
"sr": [
|
| 284 |
-
["А", "Б", "В", "Г", "Д", "Ђ", "Е", "Ж", "З", "И", "Ј"],
|
| 285 |
-
["К", "Л", "Љ", "М", "Н", "Њ", "О", "П", "Р", "С", "Т", "Ћ"],
|
| 286 |
-
["У", "Ф", "Х", "Ц", "Ч", "Џ", "Ш"]
|
| 287 |
-
],
|
| 288 |
-
"mk": [
|
| 289 |
-
["А", "Б", "В", "Г", "Д", "Ѓ", "Е", "Ж", "З", "И", "Ј"],
|
| 290 |
-
["К", "Л", "Љ", "М", "Н", "Њ", "О", "П", "Р", "С", "Т", "Ќ"],
|
| 291 |
-
["У", "Ф", "Х", "Ц", "Ч", "Џ", "Ш"]
|
| 292 |
-
],
|
| 293 |
-
"sq": [
|
| 294 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ç"],
|
| 295 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ë", "Ñ"],
|
| 296 |
-
["Z", "X", "C", "V", "B", "N", "M", "SH", "XH", "TH", "DH"]
|
| 297 |
-
],
|
| 298 |
-
"is": [
|
| 299 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ð", "Æ"],
|
| 300 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ö"],
|
| 301 |
-
["Z", "X", "C", "V", "B", "N", "M", "Þ", "Ý"]
|
| 302 |
-
],
|
| 303 |
-
"ga": [
|
| 304 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Á", "É", "Í"],
|
| 305 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ó", "Ú"],
|
| 306 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 307 |
-
],
|
| 308 |
-
"cy": [
|
| 309 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 310 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 311 |
-
["Z", "X", "C", "V", "B", "N", "M", "Ff", "Ng", "Rh"]
|
| 312 |
-
],
|
| 313 |
-
"eu": [
|
| 314 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ñ"],
|
| 315 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "TZ", "TX"],
|
| 316 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 317 |
-
],
|
| 318 |
-
"ca": [
|
| 319 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ç", "L·L"],
|
| 320 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "NY"],
|
| 321 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 322 |
-
],
|
| 323 |
-
"gl": [
|
| 324 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 325 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ñ"],
|
| 326 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 327 |
-
],
|
| 328 |
-
"id": [
|
| 329 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 330 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 331 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 332 |
-
],
|
| 333 |
-
"ms": [
|
| 334 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 335 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 336 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 337 |
-
],
|
| 338 |
-
"tl": [
|
| 339 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 340 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 341 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 342 |
-
],
|
| 343 |
-
"sw": [
|
| 344 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 345 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 346 |
-
["Z", "X", "C", "V", "B", "N", "M", "NG'", "CH", "SH"]
|
| 347 |
-
],
|
| 348 |
-
"af": [
|
| 349 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 350 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 351 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 352 |
-
],
|
| 353 |
-
"zu": [
|
| 354 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 355 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 356 |
-
["Z", "X", "C", "V", "B", "N", "M", "C", "Q", "X"]
|
| 357 |
-
],
|
| 358 |
-
"xh": [
|
| 359 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 360 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 361 |
-
["Z", "X", "C", "V", "B", "N", "M", "C", "Q", "X"]
|
| 362 |
-
],
|
| 363 |
-
"am": [
|
| 364 |
-
["ሀ", "ለ", "ሐ", "መ", "ሠ", "ረ", "ሰ", "ሸ", "ቀ", "በ", "ተ", "ቸ", "ኀ"],
|
| 365 |
-
["ነ", "ኘ", "አ", "ከ", "ኸ", "ወ", "ዐ", "ዘ", "ዠ", "የ", "ደ", "ጀ", "ገ"],
|
| 366 |
-
["ጠ", "ጨ", "ጰ", "ጸ", "ፀ", "ፊ", "ፒ", "ፓ"]
|
| 367 |
-
],
|
| 368 |
-
"yo": [
|
| 369 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ṣ"],
|
| 370 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ẹ", "Ọ", "Ṣ"],
|
| 371 |
-
["Z", "X", "C", "V", "B", "N", "M", "Gb", "Ṣ"]
|
| 372 |
-
],
|
| 373 |
-
"ig": [
|
| 374 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 375 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ị", "Ọ", "Ụ"],
|
| 376 |
-
["Z", "X", "C", "V", "B", "N", "M", "Ch", "Gb", "Kp", "Nw", "Ny"]
|
| 377 |
-
],
|
| 378 |
-
"ha": [
|
| 379 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 380 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 381 |
-
["Z", "X", "C", "V", "B", "N", "M", "��", "Ɓ", "Ɗ", "Ƴ"]
|
| 382 |
-
],
|
| 383 |
-
"so": [
|
| 384 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 385 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 386 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 387 |
-
],
|
| 388 |
-
"ti": [
|
| 389 |
-
["ሀ", "ለ", "ሐ", "መ", "ሠ", "ረ", "ሰ", "ሸ", "ቀ", "በ", "ተ", "ቸ", "ኀ"],
|
| 390 |
-
["ነ", "ኘ", "አ", "ከ", "ኸ", "ወ", "ዐ", "ዘ", "ዠ", "የ", "ደ", "ጀ", "ገ"],
|
| 391 |
-
["ጠ", "ጨ", "ጰ", "ጸ", "ፀ", "ፊ", "ፒ", "ፓ"]
|
| 392 |
-
],
|
| 393 |
-
"om": [
|
| 394 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 395 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 396 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 397 |
-
],
|
| 398 |
-
"rw": [
|
| 399 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 400 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 401 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 402 |
-
],
|
| 403 |
-
"rn": [
|
| 404 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 405 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 406 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 407 |
-
],
|
| 408 |
-
"ny": [
|
| 409 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 410 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 411 |
-
["Z", "X", "C", "V", "B", "N", "M", "Ch", "Ng'", "Ny"]
|
| 412 |
-
],
|
| 413 |
-
"sn": [
|
| 414 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 415 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 416 |
-
["Z", "X", "C", "V", "B", "N", "M", "Dz", "Sv", "Nz"]
|
| 417 |
-
],
|
| 418 |
-
"st": [
|
| 419 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 420 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 421 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 422 |
-
],
|
| 423 |
-
"tn": [
|
| 424 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 425 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 426 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 427 |
-
],
|
| 428 |
-
"ts": [
|
| 429 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 430 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 431 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 432 |
-
],
|
| 433 |
-
"ss": [
|
| 434 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 435 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 436 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 437 |
-
],
|
| 438 |
-
"ve": [
|
| 439 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 440 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 441 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 442 |
-
],
|
| 443 |
-
"nr": [
|
| 444 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 445 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 446 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 447 |
-
],
|
| 448 |
-
"nso": [
|
| 449 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 450 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 451 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 452 |
-
],
|
| 453 |
-
"mg": [
|
| 454 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 455 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 456 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 457 |
-
],
|
| 458 |
-
"mi": [
|
| 459 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 460 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 461 |
-
["Z", "X", "C", "V", "B", "N", "M", "Wh", "Ng"]
|
| 462 |
-
],
|
| 463 |
-
"sm": [
|
| 464 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 465 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 466 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 467 |
-
],
|
| 468 |
-
"to": [
|
| 469 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 470 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 471 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 472 |
-
],
|
| 473 |
-
"fj": [
|
| 474 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 475 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 476 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 477 |
-
],
|
| 478 |
-
"haw": [
|
| 479 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 480 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 481 |
-
["Z", "X", "C", "V", "B", "N", "M", "H", "K", "L", "W"]
|
| 482 |
-
],
|
| 483 |
-
"jv": [
|
| 484 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 485 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 486 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 487 |
-
],
|
| 488 |
-
"su": [
|
| 489 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 490 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 491 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 492 |
-
],
|
| 493 |
-
"ceb": [
|
| 494 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 495 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 496 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 497 |
-
],
|
| 498 |
-
"hil": [
|
| 499 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 500 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 501 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 502 |
-
],
|
| 503 |
-
"war": [
|
| 504 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 505 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 506 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 507 |
-
],
|
| 508 |
-
"ilo": [
|
| 509 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 510 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 511 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 512 |
-
],
|
| 513 |
-
"bcl": [
|
| 514 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 515 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 516 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 517 |
-
],
|
| 518 |
-
"pam": [
|
| 519 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 520 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 521 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 522 |
-
],
|
| 523 |
-
"pag": [
|
| 524 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "NG"],
|
| 525 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 526 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 527 |
-
],
|
| 528 |
-
"zh-yue": [
|
| 529 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 530 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 531 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 532 |
-
],
|
| 533 |
-
"wuu": [
|
| 534 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 535 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 536 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 537 |
-
],
|
| 538 |
-
"nan": [
|
| 539 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 540 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 541 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 542 |
-
],
|
| 543 |
-
"hak": [
|
| 544 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 545 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 546 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 547 |
-
],
|
| 548 |
-
"gan": [
|
| 549 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 550 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 551 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 552 |
-
],
|
| 553 |
-
"hsn": [
|
| 554 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 555 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 556 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 557 |
-
],
|
| 558 |
-
"cdo": [
|
| 559 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 560 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 561 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 562 |
-
],
|
| 563 |
-
"cjy": [
|
| 564 |
-
["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
|
| 565 |
-
["上", "下", "左", "右", "前", "后", "大", "小", "多", "少"],
|
| 566 |
-
["人", "口", "手", "日", "月", "水", "火", "山", "石", "田", "土", "木", "禾", "米", "竹", "金", "玉", "门", "马", "鱼", "鸟", "龙"]
|
| 567 |
-
],
|
| 568 |
-
"kok": [
|
| 569 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 570 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 571 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह"]
|
| 572 |
-
],
|
| 573 |
-
"or": [
|
| 574 |
-
["ଅ", "ଆ", "ଇ", "ଈ", "ଉ", "ଊ", "ଋ", "ଏ", "ଐ", "ଓ", "ଔ"],
|
| 575 |
-
["କ", "ଖ", "ଗ", "ଘ", "ଙ", "ଚ", "ଛ", "ଜ", "ଝ", "ଞ"],
|
| 576 |
-
["ଟ", "ଠ", "ଡ", "ଢ", "ଣ", "ତ", "ଥ", "ଦ", "ଧ", "ନ", "ପ", "ଫ", "ବ", "ଭ", "ମ", "ଯ", "ର", "ଲ", "ଵ", "ଶ", "ଷ", "ସ", "ହ", "ଳ", "କ୍ଷ", "ଜ୍ଞ"]
|
| 577 |
-
],
|
| 578 |
-
"as": [
|
| 579 |
-
["অ", "আ", "ই", "ঈ", "উ", "ঊ", "ঋ", "এ", "ঐ", "ও", "ঔ"],
|
| 580 |
-
["ক", "খ", "গ", "ঘ", "ঙ", "চ", "ছ", "জ", "ঝ", "ঞ"],
|
| 581 |
-
["ট", "ঠ", "ড", "ঢ", "ণ", "ত", "থ", "দ", "ধ", "ন", "প", "ফ", "ব", "ভ", "ম", "য", "ৰ", "ল", "ৱ", "শ", "ষ", "স", "হ", "ক্ষ", "জ্ঞ"]
|
| 582 |
-
],
|
| 583 |
-
"sat": [
|
| 584 |
-
["ᱚ", "ᱟ", "ᱤ", "ᱤᱤ", "ᱩ", "ᱩᱩ", "ᱮ", "ᱮᱮ", "ᱚᱮ", "ᱳ"],
|
| 585 |
-
["ᱠ", "ᱠᱷ", "ᱜ", "ᱜᱷ", "ᱝ", "ᱪ", "ᱪᱷ", "ᱡ", "ᱡᱷ", "ᱧ"],
|
| 586 |
-
["ᱴ", "ᱴᱷ", "ᱰ", "ᱰᱷ", "ᱬ", "ᱛ", "ᱛᱷ", "ᱫ", "ᱫᱷ", "ᱱ", "ᱯ", "ᱯᱷ", "ᱵ", "ᱵᱷ", "ᱢ", "ᱭ", "ᱨ", "ᱞ", "ᱶ", "ᱥ", "ᱦ"]
|
| 587 |
-
],
|
| 588 |
-
"sd": [
|
| 589 |
-
["ا", "ب", "پ", "ت", "ٿ", "ج", "چ", "ح", "خ", "د"],
|
| 590 |
-
["ڌ", "ڏ", "ر", "ز", "س", "ش", "ص", "ض", "ط", "ظ"],
|
| 591 |
-
["ع", "غ", "ف", "ق", "ڪ", "گ", "ڳ", "نگ", "ل", "م", "ن", "و", "ه", "ي"]
|
| 592 |
-
],
|
| 593 |
-
"ks": [
|
| 594 |
-
["ا", "آ", "إ", "اِ", "اٖ", "اُ", "اٗ", "ے", "ےٕ", "وٕ"],
|
| 595 |
-
["ک", "کھ", "گ", "گھ", "چ", "چھ", "ج", "جھ", "ٹ", "ٹھ"],
|
| 596 |
-
["ڈ", "ڈھ", "ڑ", "ت", "تھ", "د", "دھ", "ن", "پ", "پھ", "ب", "بھ", "م", "ی", "ر", "ل", "و", "س", "ش", "ز", "ہ"]
|
| 597 |
-
],
|
| 598 |
-
"mai": [
|
| 599 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 600 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 601 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह"]
|
| 602 |
-
],
|
| 603 |
-
"mni": [
|
| 604 |
-
["ꯑ", "ꯂ", "ꯃ", "ꯄ", "ꯅ", "ꯆ", "ꯇ", "ꯈ", "ꯉ", "ꯋ"],
|
| 605 |
-
["ꯌ", "ꯍ", "ꯎ", "ꯏ", "ꯐ", "ꯑꯣ", "ꯑꯥ", "ꯑꯤ", "ꯑꯨ", "ꯑꯦ"],
|
| 606 |
-
["ꯑꯩ", "ꯑꯧ", "ꯑꯪ", "ꯑ꯫", "ꯑ꯱", "ꯑ꯲", "ꯑ꯳", "ꯑ꯴", "ꯑ꯵", "ꯑ꯶"]
|
| 607 |
-
],
|
| 608 |
-
"brx": [
|
| 609 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 610 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 611 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह"]
|
| 612 |
-
],
|
| 613 |
-
"doi": [
|
| 614 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ए", "ऐ", "ओ", "औ"],
|
| 615 |
-
["क", "ख", "ग", "घ", "च", "छ", "ज", "झ", "ट", "ठ"],
|
| 616 |
-
["ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह"]
|
| 617 |
-
],
|
| 618 |
-
"sa": [
|
| 619 |
-
["अ", "आ", "इ", "ई", "उ", "ऊ", "ऋ", "ए", "ऐ", "ओ", "औ"],
|
| 620 |
-
["क", "ख", "ग", "घ", "ङ", "च", "छ", "ज", "झ", "ञ"],
|
| 621 |
-
["ट", "ठ", "ड", "ढ", "ण", "त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श", "ष", "स", "ह"]
|
| 622 |
-
],
|
| 623 |
-
"dv": [
|
| 624 |
-
["އ", "ވ", "މ", "ފ", "ދ", "ތ", "ލ", "ގ", "ޏ", "ސ"],
|
| 625 |
-
["ހ", "ށ", "ނ", "ރ", "ބ", "ޅ", "ކ", "އ", "ވ", "މ"],
|
| 626 |
-
["ފ", "ދ", "ތ", "ލ", "ގ", "ޏ", "ސ", "ހ", "ށ", "ނ", "ރ", "ބ", "ޅ", "ކ"]
|
| 627 |
-
],
|
| 628 |
-
"bo": [
|
| 629 |
-
["ཀ", "ཁ", "ག", "ང", "ཅ", "ཆ", "ཇ", "ཉ", "ཊ", "ཋ"],
|
| 630 |
-
["ཌ", "ཎ", "ཏ", "ཐ", "ད", "ན", "པ", "ཕ", "བ", "མ"],
|
| 631 |
-
["ཙ", "ཚ", "ཛ", "ཝ", "ཞ", "ཟ", "འ", "ཡ", "ར", "ལ", "ཤ", "ཥ", "ས", "ཧ", "ཨ"]
|
| 632 |
-
],
|
| 633 |
-
"dz": [
|
| 634 |
-
["ཀ", "ཁ", "ག", "ང", "ཅ", "ཆ", "ཇ", "ཉ", "ཊ", "ཋ"],
|
| 635 |
-
["ཌ", "ཎ", "ཏ", "ཐ", "ད", "ན", "པ", "ཕ", "བ", "མ"],
|
| 636 |
-
["ཙ", "ཚ", "ཛ", "ཝ", "ཞ", "ཟ", "འ", "ཡ", "ར", "ལ", "ཤ", "ཥ", "ས", "ཧ", "ཨ"]
|
| 637 |
-
],
|
| 638 |
-
"ug": [
|
| 639 |
-
["ا", "ە", "ب", "پ", "ت", "ج", "چ", "ح", "خ", "د"],
|
| 640 |
-
["ر", "ز", "ژ", "س", "ش", "غ", "ف", "ڭ", "ك", "گ"],
|
| 641 |
-
["ل", "م", "ن", "ۋ", "و", "ۇ", "ۆ", "ۈ", "ې", "ى", "ي", "ە", "ھ"]
|
| 642 |
-
],
|
| 643 |
-
"kk": [
|
| 644 |
-
["А", "Ә", "Б", "В", "Г", "Ғ", "Д", "Е", "Ж", "З"],
|
| 645 |
-
["И", "Й", "К", "Қ", "Л", "М", "Н", "Ң", "О", "Ө"],
|
| 646 |
-
["П", "Р", "С", "Т", "У", "Ұ", "Ү", "Ф", "Х", "Һ", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "І", "Ь", "Э", "Ю", "Я"]
|
| 647 |
-
],
|
| 648 |
-
"ky": [
|
| 649 |
-
["А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И"],
|
| 650 |
-
["Й", "К", "Л", "М", "Н", "Ң", "О", "Ө", "П", "Р"],
|
| 651 |
-
["С", "Т", "У", "Ү", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь", "Э", "Ю", "Я"]
|
| 652 |
-
],
|
| 653 |
-
"tg": [
|
| 654 |
-
["А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И"],
|
| 655 |
-
["Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т"],
|
| 656 |
-
["У", "Ф", "Х", "Ҳ", "Ч", "Ҷ", "Ш", "Ъ", "Э", "Ю", "Я"]
|
| 657 |
-
],
|
| 658 |
-
"tk": [
|
| 659 |
-
["А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И"],
|
| 660 |
-
["Й", "К", "Л", "М", "Н", "Ң", "О", "Ө", "П", "Р"],
|
| 661 |
-
["С", "Т", "У", "Ү", "Ф", "Х", "Һ", "Ч", "Ш", "Ы"]
|
| 662 |
-
],
|
| 663 |
-
"uz": [
|
| 664 |
-
["А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И"],
|
| 665 |
-
["Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т"],
|
| 666 |
-
["У", "Ф", "Х", "Ҳ", "Ч", "Ш", "Ъ", "Э", "Ю", "Я"]
|
| 667 |
-
],
|
| 668 |
-
"mn": [
|
| 669 |
-
["А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И"],
|
| 670 |
-
["Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т"],
|
| 671 |
-
["У", "Ү", "Ф", "Х", "Һ", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь", "Э", "Ю", "Я"]
|
| 672 |
-
],
|
| 673 |
-
"ti": [
|
| 674 |
-
["ሀ", "ለ", "ሐ", "መ", "ሠ", "ረ", "ሰ", "ሸ", "ቀ", "በ", "ተ", "ቸ", "ኀ"],
|
| 675 |
-
["ነ", "ኘ", "አ", "ከ", "ኸ", "ወ", "ዐ", "ዘ", "ዠ", "የ", "ደ", "ጀ", "ገ"],
|
| 676 |
-
["ጠ", "ጨ", "ጰ", "ጸ", "ፀ", "ፊ", "ፒ", "ፓ"]
|
| 677 |
-
],
|
| 678 |
-
"chr": [
|
| 679 |
-
["Ꭰ", "Ꭱ", "Ꭲ", "Ꭳ", "Ꭴ", "Ꭵ", "Ꭶ", "Ꭷ", "Ꭸ", "Ꭹ"],
|
| 680 |
-
["Ꭺ", "Ꭻ", "Ꭼ", "Ꭽ", "Ꭾ", "Ꭿ", "Ꮀ", "Ꮁ", "Ꮂ", "Ꮃ"],
|
| 681 |
-
["Ꮄ", "Ꮅ", "Ꮆ", "Ꮇ", "Ꮈ", "Ꮉ", "Ꮊ", "Ꮋ", "Ꮌ", "Ꮍ", "Ꮎ", "Ꮏ", "Ꮐ", "Ꮑ", "Ꮒ", "Ꮓ", "Ꮔ", "Ꮕ", "Ꮖ", "Ꮗ", "Ꮘ", "Ꮙ", "Ꮚ", "Ꮛ", "Ꮜ", "Ꮝ", "Ꮞ", "Ꮟ", "Ꮠ", "Ꮡ", "Ꮢ", "Ꮣ", "Ꮤ", "Ꮥ", "Ꮦ", "Ꮧ", "Ꮨ", "Ꮩ", "Ꮪ", "Ꮫ", "Ꮬ", "Ꮭ", "Ꮮ", "Ꮯ", "Ꮰ", "Ꮱ", "Ꮲ", "Ꮳ", "Ꮴ", "Ꮵ", "Ꮶ", "Ꮷ", "Ꮸ", "Ꮹ", "Ꮺ", "Ꮻ", "Ꮼ", "Ꮽ", "Ꮾ", "Ꮿ"]
|
| 682 |
-
],
|
| 683 |
-
"iu": [
|
| 684 |
-
["ᐃ", "ᐄ", "ᐅ", "ᐆ", "ᐊ", "ᐋ", "ᐱ", "ᐲ", "ᐳ", "ᐴ"],
|
| 685 |
-
["ᐸ", "ᐹ", "ᑎ", "ᑏ", "ᑐ", "ᑑ", "ᑕ", "ᑖ", "ᑭ", "ᑮ"],
|
| 686 |
-
["ᑯ", "ᑰ", "ᑲ", "ᑳ", "ᒋ", "ᒌ", "ᒍ", "ᒎ", "ᒐ", "ᒑ", "ᒥ", "ᒦ", "ᒧ", "ᒨ", "ᒪ", "ᒫ", "ᓂ", "ᓃ", "ᓄ", "ᓅ", "ᓇ", "ᓈ", "ᓯ", "ᓰ", "ᓱ", "ᓲ", "ᓴ", "ᓵ", "ᔨ", "ᔩ", "ᔪ", "ᔫ", "ᔭ", "ᔮ"]
|
| 687 |
-
],
|
| 688 |
-
"oj": [
|
| 689 |
-
["ᐊ", "ᐋ", "ᐁ", "ᐃ", "ᐄ", "ᐅ", "ᐆ", "ᐸ", "ᐹ", "ᑉ"],
|
| 690 |
-
["ᑎ", "ᑏ", "ᑦ", "ᑭ", "ᑮ", "ᒃ", "ᒋ", "ᒌ", "ᒡ", "ᒥ"],
|
| 691 |
-
["ᒦ", "ᒻ", "ᓂ", "ᓃ", "ᓐ", "ᓯ", "ᓰ", "ᔅ", "ᔨ", "ᔩ", "ᔾ", "ᕀ"]
|
| 692 |
-
],
|
| 693 |
-
"nv": [
|
| 694 |
-
["A", "B", "CH", "D", "DL", "E", "G", "GH", "H", "HW"],
|
| 695 |
-
["I", "J", "K", "KW", "L", "Ł", "M", "N", "O", "S"],
|
| 696 |
-
["SH", "T", "TŁ", "TS", "TZ", "U", "W", "Y", "ZH", "ʼ"]
|
| 697 |
-
],
|
| 698 |
-
"lkt": [
|
| 699 |
-
["A", "B", "Č", "Čȟ", "E", "G", "Ǧ", "H", "Ȟ", "I"],
|
| 700 |
-
["K", "Ȟ", "L", "M", "N", "O", "P", "R", "S", "Š"],
|
| 701 |
-
["T", "Tȟ", "U", "W", "Y", "Z", "Ž", "ŋ", "ʼ"]
|
| 702 |
-
],
|
| 703 |
-
"dak": [
|
| 704 |
-
["A", "B", "Č", "Čȟ", "E", "G", "Ǧ", "H", "Ȟ", "I"],
|
| 705 |
-
["K", "Ȟ", "L", "M", "N", "O", "P", "R", "S", "Š"],
|
| 706 |
-
["T", "Tȟ", "U", "W", "Y", "Z", "Ž", "ŋ", "ʼ"]
|
| 707 |
-
],
|
| 708 |
-
"cr": [
|
| 709 |
-
["ᐊ", "ᐋ", "ᐁ", "ᐃ", "ᐄ", "ᐅ", "ᐆ", "ᐸ", "ᐹ", "ᑉ"],
|
| 710 |
-
["ᑎ", "ᑏ", "ᑦ", "ᑭ", "ᑮ", "ᒃ", "ᒋ", "ᒌ", "ᒡ", "ᒥ"],
|
| 711 |
-
["ᒦ", "ᒻ", "ᓂ", "ᓃ", "ᓐ", "ᓯ", "ᓰ", "ᔅ", "ᔨ", "ᔩ", "ᔾ", "ᕀ"]
|
| 712 |
-
],
|
| 713 |
-
"qu": [
|
| 714 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 715 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 716 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "LL", "Ñ", "QQ", "RR", "SH", "W"]
|
| 717 |
-
],
|
| 718 |
-
"ay": [
|
| 719 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 720 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 721 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 722 |
-
],
|
| 723 |
-
"gn": [
|
| 724 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 725 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ñ", "G̃"],
|
| 726 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 727 |
-
],
|
| 728 |
-
"nah": [
|
| 729 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 730 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 731 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "CU", "HU", "TL", "TZ", "X"]
|
| 732 |
-
],
|
| 733 |
-
"yua": [
|
| 734 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 735 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 736 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "PP"]
|
| 737 |
-
],
|
| 738 |
-
"hus": [
|
| 739 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 740 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 741 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "TZ"]
|
| 742 |
-
],
|
| 743 |
-
"oto": [
|
| 744 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 745 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 746 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "NG", "TS"]
|
| 747 |
-
],
|
| 748 |
-
"mix": [
|
| 749 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 750 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 751 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "NG", "TS"]
|
| 752 |
-
],
|
| 753 |
-
"zap": [
|
| 754 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 755 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 756 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "NG", "TS"]
|
| 757 |
-
],
|
| 758 |
-
"tar": [
|
| 759 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 760 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 761 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "TS"]
|
| 762 |
-
],
|
| 763 |
-
"toi": [
|
| 764 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 765 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 766 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 767 |
-
],
|
| 768 |
-
"sna": [
|
| 769 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 770 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 771 |
-
["Z", "X", "C", "V", "B", "N", "M", "CH", "DZ", "NG'", "NY", "SV"]
|
| 772 |
-
],
|
| 773 |
-
"nde": [
|
| 774 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 775 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 776 |
-
["Z", "X", "C", "V", "B", "N", "M", "C", "Q", "X"]
|
| 777 |
-
],
|
| 778 |
-
"ven": [
|
| 779 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 780 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 781 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 782 |
-
],
|
| 783 |
-
"nso": [
|
| 784 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 785 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 786 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 787 |
-
],
|
| 788 |
-
"ssw": [
|
| 789 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 790 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 791 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 792 |
-
],
|
| 793 |
-
"tso": [
|
| 794 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 795 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 796 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 797 |
-
]
|
| 798 |
-
}
|
| 799 |
-
|
| 800 |
-
# Default QWERTY keyboard for unsupported languages
|
| 801 |
-
DEFAULT_KEYBOARD = [
|
| 802 |
-
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 803 |
-
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 804 |
-
["Z", "X", "C", "V", "B", "N", "M"]
|
| 805 |
-
]
|
| 806 |
-
|
| 807 |
-
# Language codes mapped to countries/regions for GPS-based word selection
|
| 808 |
-
# Extended to cover most populous and commonly visited countries
|
| 809 |
-
NYELV_ORSZAG_TERKEP = {
|
| 810 |
-
# Major global languages (most spoken/visited)
|
| 811 |
-
"en": ["GB", "US", "IE", "AU", "NZ", "CA", "ZA", "NG", "KE", "GH", "UG", "TZ", "ZW", "BW", "NA", "SZ", "LS", "MW", "ZM", "SG", "MY", "PH", "IN", "PK", "BD", "LK"], # English
|
| 812 |
-
"zh": ["CN", "TW", "HK", "MO"], # Chinese
|
| 813 |
-
"hi": ["IN"], # Hindi
|
| 814 |
-
"es": ["ES", "MX", "AR", "CO", "PE", "VE", "CL", "EC", "GT", "CU", "BO", "DO", "HN", "PY", "SV", "NI", "CR", "PA", "UY", "GQ", "PR"], # Spanish
|
| 815 |
-
"ar": ["EG", "SA", "AE", "DZ", "IQ", "MA", "YE", "SY", "TN", "JO", "LY", "LB", "PS", "OM", "KW", "MR", "QA", "BH"], # Arabic
|
| 816 |
-
"pt": ["PT", "BR", "AO", "MZ", "GW", "TL", "CV", "ST"], # Portuguese
|
| 817 |
-
"bn": ["BD"], # Bengali
|
| 818 |
-
"ru": ["RU", "BY", "KZ"], # Russian
|
| 819 |
-
"ja": ["JP"], # Japanese
|
| 820 |
-
"jv": ["ID"], # Javanese (Indonesia)
|
| 821 |
-
"de": ["DE", "AT", "CH", "LI", "LU", "BE"], # German
|
| 822 |
-
"fr": ["FR", "BE", "CH", "LU", "MC", "CA", "HT", "SN", "ML", "BF", "NE", "TD", "MG", "CM", "CI", "GN", "RW", "BI", "DJ", "GA", "CG", "CD", "CF", "KM"], # French
|
| 823 |
-
"it": ["IT", "CH", "SM", "VA"], # Italian
|
| 824 |
-
"tr": ["TR"], # Turkish
|
| 825 |
-
"ko": ["KR"], # Korean
|
| 826 |
-
"vi": ["VN"], # Vietnamese
|
| 827 |
-
"th": ["TH"], # Thai
|
| 828 |
-
"pl": ["PL"], # Polish
|
| 829 |
-
"uk": ["UA"], # Ukrainian
|
| 830 |
-
"nl": ["NL", "BE", "SR"], # Dutch
|
| 831 |
-
"ro": ["RO", "MD"], # Romanian
|
| 832 |
-
"cs": ["CZ"], # Czech
|
| 833 |
-
"el": ["GR", "CY"], # Greek
|
| 834 |
-
"hu": ["HU"], # Hungarian
|
| 835 |
-
"sv": ["SE", "FI"], # Swedish
|
| 836 |
-
"bg": ["BG"], # Bulgarian
|
| 837 |
-
"hr": ["HR", "BA"], # Croatian
|
| 838 |
-
"sk": ["SK"], # Slovak
|
| 839 |
-
"da": ["DK"], # Danish
|
| 840 |
-
"fi": ["FI"], # Finnish
|
| 841 |
-
"no": ["NO"], # Norwegian
|
| 842 |
-
"sl": ["SI"], # Slovenian
|
| 843 |
-
"et": ["EE"], # Estonian
|
| 844 |
-
"lv": ["LV"], # Latvian
|
| 845 |
-
"lt": ["LT"], # Lithuanian
|
| 846 |
-
"mt": ["MT"], # Maltese
|
| 847 |
-
"ga": ["IE"], # Irish
|
| 848 |
-
"is": ["IS"], # Icelandic
|
| 849 |
-
"he": ["IL"], # Hebrew
|
| 850 |
-
"fa": ["IR", "AF"], # Persian/Farsi
|
| 851 |
-
"ur": ["PK"], # Urdu
|
| 852 |
-
"id": ["ID"], # Indonesian
|
| 853 |
-
"ms": ["MY", "BN"], # Malay
|
| 854 |
-
"tl": ["PH"], # Filipino/Tagalog
|
| 855 |
-
"sw": ["KE", "TZ", "UG", "RW", "BI", "CD", "MG"], # Swahili
|
| 856 |
-
"af": ["ZA", "NA"], # Afrikaans
|
| 857 |
-
"am": ["ET"], # Amharic
|
| 858 |
-
"yo": ["NG"], # Yoruba
|
| 859 |
-
"zu": ["ZA"], # Zulu
|
| 860 |
-
"xh": ["ZA"], # Xhosa
|
| 861 |
-
"sq": ["AL", "XK"], # Albanian
|
| 862 |
-
"hy": ["AM"], # Armenian
|
| 863 |
-
"az": ["AZ"], # Azerbaijani
|
| 864 |
-
"eu": ["ES"], # Basque (Spain)
|
| 865 |
-
"be": ["BY"], # Belarusian
|
| 866 |
-
"bs": ["BA"], # Bosnian
|
| 867 |
-
"ca": ["ES", "AD"], # Catalan
|
| 868 |
-
"ka": ["GE"], # Georgian
|
| 869 |
-
"kk": ["KZ"], # Kazakh
|
| 870 |
-
"ky": ["KG"], # Kyrgyz
|
| 871 |
-
"mk": ["MK"], # Macedonian
|
| 872 |
-
"mn": ["MN"], # Mongolian
|
| 873 |
-
"sr": ["RS", "ME", "BA"], # Serbian
|
| 874 |
-
"uz": ["UZ"], # Uzbek
|
| 875 |
-
"tg": ["TJ"], # Tajik
|
| 876 |
-
"ne": ["NP"], # Nepali
|
| 877 |
-
"si": ["LK"], # Sinhala
|
| 878 |
-
"my": ["MM"], # Burmese
|
| 879 |
-
"km": ["KH"], # Khmer
|
| 880 |
-
"lo": ["LA"], # Lao
|
| 881 |
-
"ka": ["GE"], # Georgian
|
| 882 |
-
"ps": ["AF", "PK"], # Pashto
|
| 883 |
-
"ku": ["TR", "IQ", "IR", "SY"], # Kurdish
|
| 884 |
-
"yi": ["IL", "US"], # Yiddish
|
| 885 |
-
"cy": ["GB"], # Welsh
|
| 886 |
-
"br": ["FR"], # Breton
|
| 887 |
-
"gd": ["GB"], # Scottish Gaelic
|
| 888 |
-
"mt": ["MT"], # Maltese
|
| 889 |
-
"lb": ["LU"], # Luxembourgish
|
| 890 |
-
"fo": ["FO"], # Faroese
|
| 891 |
-
"gl": ["ES"], # Galician
|
| 892 |
-
"oc": ["FR"], # Occitan
|
| 893 |
-
"co": ["FR"], # Corsican
|
| 894 |
-
"sc": ["IT"], # Sardinian
|
| 895 |
-
"rm": ["CH"], # Romansh
|
| 896 |
-
"fy": ["NL"], # Frisian
|
| 897 |
-
"kw": ["GB"], # Cornish
|
| 898 |
-
"gv": ["IM"], # Manx
|
| 899 |
-
"an": ["ES"], # Aragonese
|
| 900 |
-
"ast": ["ES"], # Asturian
|
| 901 |
-
"ext": ["ES"], # Extremaduran
|
| 902 |
-
"mwl": ["PT"], # Mirandese
|
| 903 |
-
"wa": ["BE"], # Walloon
|
| 904 |
-
"li": ["NL", "BE"], # Limburgish
|
| 905 |
-
"nds": ["DE", "NL"], # Low German
|
| 906 |
-
"pdc": ["US"], # Pennsylvania German
|
| 907 |
-
"yi": ["IL", "US", "UA", "PL"], # Yiddish
|
| 908 |
-
"lad": ["IL", "TR"], # Ladino
|
| 909 |
-
"arn": ["CL", "AR"], # Mapudungun
|
| 910 |
-
"qu": ["PE", "BO", "EC"], # Quechua
|
| 911 |
-
"ay": ["BO", "PE"], # Aymara
|
| 912 |
-
"gn": ["PY"], # Guarani
|
| 913 |
-
"nah": ["MX"], # Nahuatl
|
| 914 |
-
"yua": ["MX"], # Yucatec Maya
|
| 915 |
-
"hus": ["MX", "GT"], # Huastec
|
| 916 |
-
"oto": ["MX"], # Otomi
|
| 917 |
-
"mix": ["MX"], # Mixtec
|
| 918 |
-
"zap": ["MX"], # Zapotec
|
| 919 |
-
"tar": ["MX"], # Tarahumara
|
| 920 |
-
"toi": ["ZM", "ZW"], # Tonga
|
| 921 |
-
"nya": ["MW"], # Chichewa
|
| 922 |
-
"sna": ["ZW"], # Shona
|
| 923 |
-
"nde": ["ZW"], # Ndebele
|
| 924 |
-
"ven": ["ZA"], # Venda
|
| 925 |
-
"tsn": ["BW", "ZA"], # Tswana
|
| 926 |
-
"nso": ["ZA"], # Northern Sotho
|
| 927 |
-
"ssw": ["SZ"], # Swati
|
| 928 |
-
"tso": ["ZA", "MZ"], # Tsonga
|
| 929 |
-
}
|
| 930 |
-
|
| 931 |
-
def orszagkodbol_nyelv(orszagkod: str) -> str:
|
| 932 |
-
"""Get language code from country code."""
|
| 933 |
-
orszagkod_felso = orszagkod.upper()
|
| 934 |
-
for nyelv, orszagok in NYELV_ORSZAG_TERKEP.items():
|
| 935 |
-
if orszagkod_felso in orszagok:
|
| 936 |
-
return nyelv
|
| 937 |
-
return "en" # Default to English instead of Hungarian
|
| 938 |
-
|
| 939 |
-
@router.get("/", response_class=HTMLResponse)
|
| 940 |
-
async def index(request: Request, access_token: str = Cookie(None)):
|
| 941 |
-
"""Home page - loads default daily game (szleng)."""
|
| 942 |
-
user = await get_current_user(access_token)
|
| 943 |
-
return templates.TemplateResponse(
|
| 944 |
-
request=request,
|
| 945 |
-
name="base.html",
|
| 946 |
-
context={"user": user, "default_kategoria": "szleng"}
|
| 947 |
-
)
|
| 948 |
-
|
| 949 |
-
@router.get("/jatek/{kategoria}", response_class=HTMLResponse)
|
| 950 |
-
async def jatek_betoltes(request: Request, kategoria: str, orszag: str = None):
|
| 951 |
-
"""Load game for specific category with optional country-based language."""
|
| 952 |
-
# If category is 'nyelv' and country is provided, detect language
|
| 953 |
-
if kategoria == "nyelv" and orszag:
|
| 954 |
-
nyelv = orszagkodbol_nyelv(orszag)
|
| 955 |
-
kategoria_nev = f"🌍 {nyelv.upper()} - NAPI SZÓ"
|
| 956 |
-
kategoria_tipus = nyelv
|
| 957 |
-
else:
|
| 958 |
-
kategoria_nev = KATEGORIA_NEVEK.get(kategoria, kategoria)
|
| 959 |
-
kategoria_tipus = kategoria
|
| 960 |
-
|
| 961 |
-
# Get keyboard layout for the category
|
| 962 |
-
billentyuzet = get_billentyuzet(kategoria_tipus)
|
| 963 |
-
|
| 964 |
-
return templates.TemplateResponse(
|
| 965 |
-
request=request,
|
| 966 |
-
name="jatek.html",
|
| 967 |
-
context={
|
| 968 |
-
"kategoria_tipus": kategoria_tipus,
|
| 969 |
-
"kategoria_nev": kategoria_nev,
|
| 970 |
-
"billentyuzet": billentyuzet
|
| 971 |
-
}
|
| 972 |
-
)
|
| 973 |
-
|
| 974 |
-
@router.get("/api/nyelv-erszagalas", response_class=HTMLResponse)
|
| 975 |
-
async def nyelv_erszagalas(request: Request):
|
| 976 |
-
"""Detect language based on country code."""
|
| 977 |
-
orszagkod = request.query_params.get("orszag", "HU")
|
| 978 |
-
nyelv = orszagkodbol_nyelv(orszagkod)
|
| 979 |
-
kategoria_nev = f"🌍 {nyelv.upper()} - NAPI SZÓ"
|
| 980 |
-
billentyuzet = get_billentyuzet(nyelv)
|
| 981 |
-
return templates.TemplateResponse(
|
| 982 |
-
request=request,
|
| 983 |
-
name="jatek.html",
|
| 984 |
-
context={
|
| 985 |
-
"kategoria_tipus": nyelv,
|
| 986 |
-
"kategoria_nev": kategoria_nev,
|
| 987 |
-
"billentyuzet": billentyuzet
|
| 988 |
-
}
|
| 989 |
-
)
|
| 990 |
-
|
| 991 |
-
def get_billentyuzet(kategoria_tipus: str) -> list:
|
| 992 |
-
"""Get keyboard layout for a specific language/category."""
|
| 993 |
-
return NYELV_BILLENTYUZET.get(kategoria_tipus, DEFAULT_KEYBOARD)
|
| 994 |
-
|
| 995 |
-
def betoltesz_szavak_fajlbol(nyelv: str) -> list:
|
| 996 |
-
"""Load words from the 1000-most-common word file for a specific language."""
|
| 997 |
-
# Map language codes to filename patterns
|
| 998 |
-
nyelv_fajl_terkep = {
|
| 999 |
-
"en": "1000-common-english-words.txt",
|
| 1000 |
-
"hu": "1000-most-common-hungarian-words.txt",
|
| 1001 |
-
"de": "1000-most-common-german-words.txt",
|
| 1002 |
-
"fr": "1000-most-common-french-words.txt",
|
| 1003 |
-
"es": "1000-most-common-spanish-words.txt",
|
| 1004 |
-
"it": "1000-most-common-italian-words.txt",
|
| 1005 |
-
"pt": "1000-most-common-portuguese-words.txt",
|
| 1006 |
-
"pl": "1000-most-common-polish-words.txt",
|
| 1007 |
-
"nl": "1000-most-common-dutch-words.txt",
|
| 1008 |
-
"sv": "1000-most-common-swedish-words.txt",
|
| 1009 |
-
"fi": "1000-most-common-finnish-words.txt",
|
| 1010 |
-
"da": "1000-most-common-danish-words.txt",
|
| 1011 |
-
"cs": "1000-most-common-czech-words.txt",
|
| 1012 |
-
"sk": "1000-most-common-slovak-words.txt",
|
| 1013 |
-
"ro": "1000-most-common-romanian-words.txt",
|
| 1014 |
-
"hr": "1000-most-common-croatian-words.txt",
|
| 1015 |
-
"sl": "1000-most-common-slovenian-words.txt",
|
| 1016 |
-
"et": "1000-most-common-estonian-words.txt",
|
| 1017 |
-
"lv": "1000-most-common-latvian-words.txt",
|
| 1018 |
-
"lt": "1000-most-common-lithuanian-words.txt",
|
| 1019 |
-
"el": "1000-most-common-greek-words.txt",
|
| 1020 |
-
"ru": "1000-most-common-russian-words.txt",
|
| 1021 |
-
"bg": "1000-most-common-bulgarian-words.txt",
|
| 1022 |
-
"af": "1000-most-common-afrikaans-words.txt",
|
| 1023 |
-
"sq": "1000-most-common-albanian-words.txt",
|
| 1024 |
-
"ar": "1000-most-common-arabic-words.txt",
|
| 1025 |
-
"hy": "1000-most-common-armenian-words.txt",
|
| 1026 |
-
"az": "1000-most-common-azerbaijani-words.txt",
|
| 1027 |
-
"eu": "1000-most-common-basque-words.txt",
|
| 1028 |
-
"be": "1000-most-common-belarusian-words.txt",
|
| 1029 |
-
"bn": "1000-most-common-bengali-words.txt",
|
| 1030 |
-
"bs": "1000-most-common-bosnian-words.txt",
|
| 1031 |
-
"ca": "1000-most-common-catalan-words.txt",
|
| 1032 |
-
"ceb": "1000-most-common-cebuano-words.txt",
|
| 1033 |
-
"ny": "1000-most-common-chichewa-words.txt",
|
| 1034 |
-
"zh": "1000-most-common-chinese-words.txt",
|
| 1035 |
-
"co": "1000-most-common-corsican-words.txt",
|
| 1036 |
-
"eo": "1000-most-common-esperanto-words.txt",
|
| 1037 |
-
"tl": "1000-most-common-filipino-words.txt",
|
| 1038 |
-
"fy": "1000-most-common-frisian-words.txt",
|
| 1039 |
-
"gl": "1000-most-common-galician-words.txt",
|
| 1040 |
-
"ka": "1000-most-common-georgian-words.txt",
|
| 1041 |
-
"gu": "1000-most-common-gujarati-words.txt",
|
| 1042 |
-
"ht": "1000-most-common-haitian-words.txt",
|
| 1043 |
-
"ha": "1000-most-common-hausa-words.txt",
|
| 1044 |
-
"haw": "1000-most-common-hawaiian-words.txt",
|
| 1045 |
-
"he": "1000-most-common-hebrew-words.txt",
|
| 1046 |
-
"hi": "1000-most-common-hindi-words.txt",
|
| 1047 |
-
"hmn": "1000-most-common-hmong-words.txt",
|
| 1048 |
-
"is": "1000-most-common-icelandic-words.txt",
|
| 1049 |
-
"ig": "1000-most-common-igbo-words.txt",
|
| 1050 |
-
"id": "1000-most-common-indonesian-words.txt",
|
| 1051 |
-
"ga": "1000-most-common-irish-words.txt",
|
| 1052 |
-
"ja": "1000-most-common-japanese-words.txt",
|
| 1053 |
-
"jv": "1000-most-common-javanese-words.txt",
|
| 1054 |
-
"kn": "1000-most-common-kannada-words.txt",
|
| 1055 |
-
"kk": "1000-most-common-kazakh-words.txt",
|
| 1056 |
-
"km": "1000-most-common-khmer-words.txt",
|
| 1057 |
-
"ko": "1000-most-common-korean-words.txt",
|
| 1058 |
-
"ku": "1000-most-common-kurdish-words.txt",
|
| 1059 |
-
"ky": "1000-most-common-kyrgyz-words.txt",
|
| 1060 |
-
"lo": "1000-most-common-lao-words.txt",
|
| 1061 |
-
"la": "1000-most-common-latin-words.txt",
|
| 1062 |
-
"lb": "1000-most-common-luxembourgish-words.txt",
|
| 1063 |
-
"mk": "1000-most-common-macedonian-words.txt",
|
| 1064 |
-
"mg": "1000-most-common-malagasy-words.txt",
|
| 1065 |
-
"ml": "1000-most-common-malayalam-words.txt",
|
| 1066 |
-
"ms": "1000-most-common-malaysian-words.txt",
|
| 1067 |
-
"mt": "1000-most-common-maltese-words.txt",
|
| 1068 |
-
"mi": "1000-most-common-maori-words.txt",
|
| 1069 |
-
"mr": "1000-most-common-marathi-words.txt",
|
| 1070 |
-
"mn": "1000-most-common-mongolian-words.txt",
|
| 1071 |
-
"my": "1000-most-common-myanmar-words.txt",
|
| 1072 |
-
"ne": "1000-most-common-nepali-words.txt",
|
| 1073 |
-
"no": "1000-most-common-norwegian-words.txt",
|
| 1074 |
-
"ps": "1000-most-common-pashto-words.txt",
|
| 1075 |
-
"fa": "1000-most-common-persian-words.txt",
|
| 1076 |
-
"pa": "1000-most-common-punjabi-words.txt",
|
| 1077 |
-
"sr": "1000-most-common-serbian-words.txt",
|
| 1078 |
-
"st": "1000-most-common-sesotho-words.txt",
|
| 1079 |
-
"si": "1000-most-common-sinhala-words.txt",
|
| 1080 |
-
"so": "1000-most-common-somali-words.txt",
|
| 1081 |
-
"su": "1000-most-common-sundanese-words.txt",
|
| 1082 |
-
"sw": "1000-most-common-swahili-words.txt",
|
| 1083 |
-
"tg": "1000-most-common-tajik-words.txt",
|
| 1084 |
-
"ta": "1000-most-common-tamil-words.txt",
|
| 1085 |
-
"te": "1000-most-common-telugu-words.txt",
|
| 1086 |
-
"th": "1000-most-common-thai-words.txt",
|
| 1087 |
-
"tr": "1000-most-common-turkish-words.txt",
|
| 1088 |
-
"uk": "1000-most-common-ukrainian-words.txt",
|
| 1089 |
-
"ur": "1000-most-common-urdu-words.txt",
|
| 1090 |
-
"uz": "1000-most-common-uzbek-words.txt",
|
| 1091 |
-
"vi": "1000-most-common-vietnamese-words.txt",
|
| 1092 |
-
"cy": "1000-most-common-welsh-words.txt",
|
| 1093 |
-
"yi": "1000-most-common-yiddish-words.txt",
|
| 1094 |
-
"yo": "1000-most-common-yoruba-words.txt",
|
| 1095 |
-
"zu": "1000-most-common-zulu-words.txt"
|
| 1096 |
-
}
|
| 1097 |
-
|
| 1098 |
-
fajlnev = nyelv_fajl_terkep.get(nyelv)
|
| 1099 |
-
if not fajlnev:
|
| 1100 |
-
return []
|
| 1101 |
-
|
| 1102 |
-
# Path to the word files - look in both static/ and the project root
|
| 1103 |
-
possible_paths = [
|
| 1104 |
-
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "static", "1000-most-common", fajlnev),
|
| 1105 |
-
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "1000-most-common", fajlnev),
|
| 1106 |
-
os.path.join("static", "1000-most-common", fajlnev),
|
| 1107 |
-
]
|
| 1108 |
-
|
| 1109 |
-
for path in possible_paths:
|
| 1110 |
-
if os.path.exists(path):
|
| 1111 |
-
try:
|
| 1112 |
-
with open(path, 'r', encoding='utf-8') as f:
|
| 1113 |
-
lines = f.readlines()
|
| 1114 |
-
# Parse lines - format is "number | word" or just "word"
|
| 1115 |
-
words = []
|
| 1116 |
-
for line in lines:
|
| 1117 |
-
line = line.strip()
|
| 1118 |
-
if not line:
|
| 1119 |
-
continue
|
| 1120 |
-
# Split by | if present
|
| 1121 |
-
if '|' in line:
|
| 1122 |
-
parts = line.split('|', 1)
|
| 1123 |
-
word = parts[1].strip() if len(parts) > 1 else parts[0].strip()
|
| 1124 |
-
else:
|
| 1125 |
-
word = line
|
| 1126 |
-
# Clean up the word - remove extra spaces, keep only letters
|
| 1127 |
-
word = ''.join(c for c in word if c.isalpha()).upper()
|
| 1128 |
-
if word and len(word) >= 3: # Only include words with at least 3 letters
|
| 1129 |
-
words.append(word)
|
| 1130 |
-
return words
|
| 1131 |
-
except Exception as e:
|
| 1132 |
-
print(f"Error loading word file {path}: {e}")
|
| 1133 |
-
return []
|
| 1134 |
-
|
| 1135 |
-
return []
|
| 1136 |
-
|
| 1137 |
-
def get_daily_word(kategoria: str = "szleng") -> str:
|
| 1138 |
-
"""Get daily word based on date - deterministic selection from word list."""
|
| 1139 |
-
today = date.today()
|
| 1140 |
-
day_seed = f"{today.isoformat()}-{kategoria}"
|
| 1141 |
-
day_hash = int(hashlib.md5(day_seed.encode()).hexdigest(), 16)
|
| 1142 |
-
|
| 1143 |
-
# Check if this is a language-based category (using 1000-most-common words)
|
| 1144 |
-
if kategoria in NYELV_BILLENTYUZET or kategoria in ['en', 'hu', 'de', 'fr', 'es', 'it', 'pt', 'pl', 'nl', 'sv', 'fi', 'da', 'cs', 'sk', 'ro', 'hr', 'sl', 'et', 'lv', 'lt', 'el', 'ru', 'bg']:
|
| 1145 |
-
words = betoltesz_szavak_fajlbol(kategoria)
|
| 1146 |
-
if words:
|
| 1147 |
-
# Filter to 5-letter words for Wordle-style game
|
| 1148 |
-
ot_betus_szavak = [w for w in words if len(w) == 5]
|
| 1149 |
-
if ot_betus_szavak:
|
| 1150 |
-
return ot_betus_szavak[day_hash % len(ot_betus_szavak)]
|
| 1151 |
-
# Fallback to any word length, but take first 5 chars
|
| 1152 |
-
if words:
|
| 1153 |
-
selected = words[day_hash % len(words)]
|
| 1154 |
-
return selected[:5].upper()
|
| 1155 |
-
|
| 1156 |
-
# Query words with category join - filter by category name (database)
|
| 1157 |
-
try:
|
| 1158 |
-
response = supabase.table(settings.TABLE_WORDS)\
|
| 1159 |
-
.select("szo, kategoriak(nev)")\
|
| 1160 |
-
.eq("kategoriak.nev", kategoria)\
|
| 1161 |
-
.execute()
|
| 1162 |
-
|
| 1163 |
-
if response.data:
|
| 1164 |
-
words = [w["szo"].upper() for w in response.data]
|
| 1165 |
-
return words[day_hash % len(words)]
|
| 1166 |
-
except Exception:
|
| 1167 |
-
pass
|
| 1168 |
-
|
| 1169 |
-
return "CRING"
|
| 1170 |
-
|
| 1171 |
-
def generate_share_text(kategoria: str, probalkozasok: int, kategoria_nev: str) -> str:
|
| 1172 |
-
"""Generate shareable text for the game result."""
|
| 1173 |
-
today = date.today().strftime("%Y.%m.%d.")
|
| 1174 |
-
emojis = "🟩" * probalkozasok + "⬛" * (6 - probalkozasok)
|
| 1175 |
-
return f"Szó-Kavalkád {today}\n{kategoria_nev}\n{probalkozasok}/6\n\n{emojis}"
|
| 1176 |
-
|
| 1177 |
-
@router.post("/ellenorzes", response_class=HTMLResponse)
|
| 1178 |
-
async def ellenoriz_tipp(request: Request):
|
| 1179 |
-
"""Check guess against answer word."""
|
| 1180 |
-
# Parse form data or JSON data
|
| 1181 |
-
try:
|
| 1182 |
-
body = await request.form()
|
| 1183 |
-
tipp = body.get("tipp", "")
|
| 1184 |
-
sor = int(body.get("sor", 0))
|
| 1185 |
-
kategoria = body.get("kategoria", "szleng")
|
| 1186 |
-
except Exception:
|
| 1187 |
-
return HTMLResponse(
|
| 1188 |
-
content="<div class='text-red-500 font-bold'>HIBA: Nem sikerült feldolgozni!</div>"
|
| 1189 |
-
)
|
| 1190 |
-
|
| 1191 |
-
tipp = tipp.upper()
|
| 1192 |
-
megfejtes = get_daily_word(kategoria)
|
| 1193 |
-
|
| 1194 |
-
n = len(megfejtes)
|
| 1195 |
-
if len(tipp) != n:
|
| 1196 |
-
return HTMLResponse(
|
| 1197 |
-
content="<div class='text-red-500 font-bold'>HIBA: Hibás karakterhossz!</div>"
|
| 1198 |
-
)
|
| 1199 |
-
|
| 1200 |
-
statuszok = ["szurke"] * n
|
| 1201 |
-
megfejtes_szamlalo = Counter(megfejtes)
|
| 1202 |
-
|
| 1203 |
-
for i in range(n):
|
| 1204 |
-
if tipp[i] == megfejtes[i]:
|
| 1205 |
-
statuszok[i] = "zold"
|
| 1206 |
-
megfejtes_szamlalo[tipp[i]] -= 1
|
| 1207 |
-
|
| 1208 |
-
for i in range(n):
|
| 1209 |
-
if statuszok[i] != "zold":
|
| 1210 |
-
if megfejtes_szamlalo.get(tipp[i], 0) > 0:
|
| 1211 |
-
statuszok[i] = "sarga"
|
| 1212 |
-
megfejtes_szamlalo[tipp[i]] -= 1
|
| 1213 |
-
|
| 1214 |
-
grid_style = f'style="grid-template-columns: repeat({n}, minmax(0, 1fr));"'
|
| 1215 |
-
html_valasz = f'<div class="wordle-sor grid gap-2 w-full animate-bounce" {grid_style}>'
|
| 1216 |
-
|
| 1217 |
-
for i in range(n):
|
| 1218 |
-
szin_class = "bg-gray-800 border-gray-900 text-gray-400"
|
| 1219 |
-
if statuszok[i] == "zold":
|
| 1220 |
-
szin_class = "bg-green-600 border-green-700 text-white scale-105"
|
| 1221 |
-
elif statuszok[i] == "sarga":
|
| 1222 |
-
szin_class = "bg-yellow-500 border-yellow-600 text-white"
|
| 1223 |
-
|
| 1224 |
-
html_valasz += (
|
| 1225 |
-
f'<div class="wordle-cella flex items-center justify-center '
|
| 1226 |
-
f'text-2xl font-bold uppercase border-2 rounded select-none '
|
| 1227 |
-
f'aspect-square {szin_class}">{tipp[i]}</div>'
|
| 1228 |
-
)
|
| 1229 |
-
html_valasz += '</div>'
|
| 1230 |
-
|
| 1231 |
-
if tipp == megfejtes:
|
| 1232 |
-
probalkozasok_szama = sor + 1
|
| 1233 |
-
share_text = generate_share_text(kategoria, probalkozasok_szama, KATEGORIA_NEVEK.get(kategoria, kategoria))
|
| 1234 |
-
# Escape the share text for HTML attribute
|
| 1235 |
-
share_text_attr = share_text.replace('"', '"')
|
| 1236 |
-
html_valasz += f"""
|
| 1237 |
-
<div hx-swap-oob="beforeend:#jatek-terulet">
|
| 1238 |
-
<div class="mt-4 p-4 bg-green-900/40 border border-green-500/30 rounded text-center w-full max-w-md">
|
| 1239 |
-
<p class="font-bold text-green-400 text-lg">🎉 GRATULÁLUNK! Sikerült!</p>
|
| 1240 |
-
<p class="text-sm text-gray-300 mt-2">{probalkozasok_szama}/6 próbálkozásból</p>
|
| 1241 |
-
<div class="mt-3 flex gap-2 justify-center">
|
| 1242 |
-
<button data-share-text="{share_text_attr}"
|
| 1243 |
-
class="share-gomb px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white font-bold rounded text-sm cursor-pointer border-0 transition">
|
| 1244 |
-
📋 Megosztás
|
| 1245 |
-
</button>
|
| 1246 |
-
</div>
|
| 1247 |
-
<p class="text-xs text-gray-500 mt-2">Játssz te is: {request.url.scheme}://{request.url.netloc}</p>
|
| 1248 |
-
</div>
|
| 1249 |
-
</div>
|
| 1250 |
-
"""
|
| 1251 |
-
|
| 1252 |
-
return HTMLResponse(content=html_valasz)
|
| 1253 |
-
|
| 1254 |
-
@router.get("/rangletra", response_class=HTMLResponse)
|
| 1255 |
-
async def rangletra(request: Request, kat: str = "szleng"):
|
| 1256 |
-
"""Display leaderboard."""
|
| 1257 |
-
response = (
|
| 1258 |
-
supabase.table(settings.TABLE_LEADERBOARD)
|
| 1259 |
-
.select("username, pontszam, ido_masodperc, is_premium")
|
| 1260 |
-
.eq("kategoria", kat)
|
| 1261 |
-
.order("pontszam.desc(),ido_masodperc.asc()")
|
| 1262 |
-
.execute()
|
| 1263 |
-
)
|
| 1264 |
-
|
| 1265 |
-
lista = []
|
| 1266 |
-
for item in response.data:
|
| 1267 |
-
lista.append({
|
| 1268 |
-
"nev": item.get("username"),
|
| 1269 |
-
"ido": item.get("ido_masodperc"),
|
| 1270 |
-
"pont": item.get("pontszam"),
|
| 1271 |
-
"is_premium": item.get("is_premium", False)
|
| 1272 |
-
})
|
| 1273 |
-
|
| 1274 |
-
toplista_adatok = list(enumerate(lista, start=1))
|
| 1275 |
-
|
| 1276 |
-
return templates.TemplateResponse(
|
| 1277 |
-
request=request,
|
| 1278 |
-
name="rangletra.html",
|
| 1279 |
-
context={"toplista": toplista_adatok}
|
| 1280 |
-
)
|
| 1281 |
-
|
| 1282 |
-
@router.get("/premium", response_class=HTMLResponse)
|
| 1283 |
-
async def premium_oldal(request: Request):
|
| 1284 |
-
"""Premium membership page."""
|
| 1285 |
-
html_tartalom = """
|
| 1286 |
-
<div class="w-full max-w-md bg-gray-950 border border-amber-500/30 rounded-xl p-6 text-center shadow-2xl animate-fade-in mx-auto">
|
| 1287 |
-
<h2 class="text-3xl font-black text-amber-400 mb-2">👑 Csatlakozz a Prémiumhoz</h2>
|
| 1288 |
-
<p class="text-gray-400 text-sm mb-6">Tüntesd el a hirdetéseket, kapj egy egyedi ikont a ranglétrán és nyiss ki +5 titkos kategóriát!</p>
|
| 1289 |
-
<div class="bg-gray-900 p-4 rounded-lg mb-6 border border-gray-800">
|
| 1290 |
-
<span class="text-xs uppercase font-bold tracking-wider text-amber-500">Egyszeri díj (Örök tagság)</span>
|
| 1291 |
-
<div class="text-3xl font-black text-white mt-1">1.490 Ft</div>
|
| 1292 |
-
</div>
|
| 1293 |
-
<button onclick="alert('Itt nyílna meg a Paddle fizetési kapu!')" class="w-full py-4 bg-gradient-to-r from-amber-500 via-yellow-500 to-amber-600 text-gray-950 font-black rounded-lg shadow-lg hover:brightness-110 active:scale-98 transition cursor-pointer uppercase tracking-wider text-sm">Vásárlás most</button>
|
| 1294 |
-
</div>
|
| 1295 |
-
"""
|
| 1296 |
-
return HTMLResponse(content=html_tartalom)
|
| 1297 |
-
|
| 1298 |
-
async def get_current_user(access_token: str = Cookie(None)):
|
| 1299 |
-
"""Get current user from access token cookie."""
|
| 1300 |
-
if not access_token:
|
| 1301 |
-
return None
|
| 1302 |
-
try:
|
| 1303 |
-
user_response = supabase.auth.get_user(access_token)
|
| 1304 |
-
return user_response.user
|
| 1305 |
-
except Exception:
|
| 1306 |
-
return None
|
| 1307 |
-
|
| 1308 |
-
return router
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/wordgame/api/routes/paddle_routes.py
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
"""Paddle payment webhook routes."""
|
| 2 |
-
import json
|
| 3 |
-
from fastapi import APIRouter, Request, Header
|
| 4 |
-
from ...core.database import supabase
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
def create_router() -> APIRouter:
|
| 8 |
-
"""Create Paddle payment webhook routes router.
|
| 9 |
-
|
| 10 |
-
Returns:
|
| 11 |
-
Configured APIRouter
|
| 12 |
-
"""
|
| 13 |
-
router = APIRouter()
|
| 14 |
-
|
| 15 |
-
@router.post("/paddle-webhook")
|
| 16 |
-
async def paddle_webhook(
|
| 17 |
-
request: Request,
|
| 18 |
-
paddle_signature: str = Header(None)
|
| 19 |
-
):
|
| 20 |
-
"""Handle Paddle payment webhooks."""
|
| 21 |
-
payload_raw = await request.body()
|
| 22 |
-
payload = json.loads(payload_raw)
|
| 23 |
-
|
| 24 |
-
event_type = payload.get("event_type")
|
| 25 |
-
|
| 26 |
-
if event_type == "transaction.completed":
|
| 27 |
-
user_id = payload["data"]["custom_data"].get("user_id")
|
| 28 |
-
if user_id:
|
| 29 |
-
supabase.table("profilok")\
|
| 30 |
-
.update({"is_premium": True})\
|
| 31 |
-
.eq("id", user_id)\
|
| 32 |
-
.execute()
|
| 33 |
-
print(f"Felhasználó {user_id} sikeresen prémiumra váltott!")
|
| 34 |
-
|
| 35 |
-
return {"status": "success"}
|
| 36 |
-
|
| 37 |
-
return router
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/wordgame/app_factory.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Közös alkalmazás-gyár a public és private appokhoz.
|
| 2 |
+
|
| 3 |
+
A `settings.APP_MODE` értéke (`"public"` vagy `"private"`) határozza meg,
|
| 4 |
+
hogy mely route-ok regisztrálódnak:
|
| 5 |
+
|
| 6 |
+
- `public` – WordGame (HF Space): játék, login/reg, ranglétra, premium
|
| 7 |
+
- `private` – Lingo (HF Space): dashboard, szobák, deck, invite, admin, paddle
|
| 8 |
+
|
| 9 |
+
Mindkét app ugyanazt a `core/` modult használja (config, database, auth),
|
| 10 |
+
csak a route-ok mások.
|
| 11 |
+
"""
|
| 12 |
+
import os
|
| 13 |
+
from fastapi import FastAPI, Request
|
| 14 |
+
from fastapi.staticfiles import StaticFiles
|
| 15 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
+
from starlette.templating import Jinja2Templates
|
| 17 |
+
from starlette.responses import HTMLResponse, RedirectResponse
|
| 18 |
+
|
| 19 |
+
from .core.config import settings
|
| 20 |
+
from .public.routes import game_routes as public_game
|
| 21 |
+
from .public.routes import auth_routes as public_auth
|
| 22 |
+
from .private.routes import (
|
| 23 |
+
dashboard_routes as private_dashboard,
|
| 24 |
+
room_routes as private_room,
|
| 25 |
+
admin_routes as private_admin,
|
| 26 |
+
paddle_routes as private_paddle,
|
| 27 |
+
slang_routes as private_slang,
|
| 28 |
+
sso_callback as private_sso,
|
| 29 |
+
)
|
| 30 |
+
from .shared.routes import health_routes
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def create_app() -> FastAPI:
|
| 34 |
+
"""Létrehozza a FastAPI alkalmazást a settings.APP_MODE alapján.
|
| 35 |
+
|
| 36 |
+
Public mód: a játék + login/register route-ok regisztrálódnak.
|
| 37 |
+
Private mód: a dashboard + szobák + admin + paddle + SSO callback.
|
| 38 |
+
|
| 39 |
+
A health check (shared) mindkét módban elérhető.
|
| 40 |
+
"""
|
| 41 |
+
app = FastAPI(
|
| 42 |
+
title=settings.APP_NAME,
|
| 43 |
+
debug=settings.DEBUG,
|
| 44 |
+
version="2.0.0",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# ------------------------------------------------------------------
|
| 48 |
+
# CORS – a másik Space + a saját domain + localhost (dev)
|
| 49 |
+
# ------------------------------------------------------------------
|
| 50 |
+
app.add_middleware(
|
| 51 |
+
CORSMiddleware,
|
| 52 |
+
allow_origins=settings.ALLOWED_ORIGINS,
|
| 53 |
+
allow_credentials=True,
|
| 54 |
+
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
| 55 |
+
allow_headers=["*"],
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# ------------------------------------------------------------------
|
| 59 |
+
# Static files (mindkét app kiszolgálja)
|
| 60 |
+
# ------------------------------------------------------------------
|
| 61 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 62 |
+
static_dir = os.path.join(os.path.dirname(current_dir), "static")
|
| 63 |
+
os.makedirs(static_dir, exist_ok=True)
|
| 64 |
+
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
| 65 |
+
|
| 66 |
+
# ------------------------------------------------------------------
|
| 67 |
+
# Templates – közös mappa (mindkét app a `templates/` mappát használja)
|
| 68 |
+
# ------------------------------------------------------------------
|
| 69 |
+
templates_dir = os.path.join(current_dir, "templates")
|
| 70 |
+
os.makedirs(templates_dir, exist_ok=True)
|
| 71 |
+
templates = Jinja2Templates(directory=templates_dir)
|
| 72 |
+
|
| 73 |
+
# ------------------------------------------------------------------
|
| 74 |
+
# Shared (health, ready)
|
| 75 |
+
# ------------------------------------------------------------------
|
| 76 |
+
app.include_router(health_routes.create_router())
|
| 77 |
+
|
| 78 |
+
# ------------------------------------------------------------------
|
| 79 |
+
# Mode-specific routes
|
| 80 |
+
# ------------------------------------------------------------------
|
| 81 |
+
if settings.is_public:
|
| 82 |
+
# Public (WordGame) – játék, login, register
|
| 83 |
+
app.include_router(
|
| 84 |
+
public_game.create_router(templates),
|
| 85 |
+
tags=["game"]
|
| 86 |
+
)
|
| 87 |
+
app.include_router(
|
| 88 |
+
public_auth.create_router(templates),
|
| 89 |
+
prefix="/auth",
|
| 90 |
+
tags=["auth"]
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# A /jatek-valaszto és a /dashboard route-ok a `public/routes/game_routes.py`-ban
|
| 94 |
+
# vannak definiálva (user-kontextussal együtt).
|
| 95 |
+
# A /dashboard a public oldalon átirányít a Lingo Space /auth/sso callback-re,
|
| 96 |
+
# ahol a user átveszi a session-t.
|
| 97 |
+
|
| 98 |
+
else:
|
| 99 |
+
# Private (Lingo) – dashboard, szobák, deck, invite, admin, paddle, SSO
|
| 100 |
+
app.include_router(
|
| 101 |
+
private_dashboard.create_router(templates),
|
| 102 |
+
prefix="/dashboard",
|
| 103 |
+
tags=["dashboard"]
|
| 104 |
+
)
|
| 105 |
+
app.include_router(
|
| 106 |
+
private_room.create_router(),
|
| 107 |
+
prefix="/szoba",
|
| 108 |
+
tags=["rooms"]
|
| 109 |
+
)
|
| 110 |
+
app.include_router(
|
| 111 |
+
private_slang.create_router(),
|
| 112 |
+
prefix="/szoba/import",
|
| 113 |
+
tags=["slang"]
|
| 114 |
+
)
|
| 115 |
+
app.include_router(
|
| 116 |
+
private_paddle.create_router(),
|
| 117 |
+
tags=["payments"]
|
| 118 |
+
)
|
| 119 |
+
app.include_router(
|
| 120 |
+
private_admin.create_router(templates),
|
| 121 |
+
tags=["admin"]
|
| 122 |
+
)
|
| 123 |
+
app.include_router(
|
| 124 |
+
private_sso.create_router(),
|
| 125 |
+
prefix="/auth",
|
| 126 |
+
tags=["auth"]
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
# ------------------------------------------------------------------
|
| 130 |
+
# 404 handler
|
| 131 |
+
# ------------------------------------------------------------------
|
| 132 |
+
@app.exception_handler(404)
|
| 133 |
+
async def custom_404_handler(request: Request, exc):
|
| 134 |
+
return templates.TemplateResponse(
|
| 135 |
+
request=request,
|
| 136 |
+
name="404.html",
|
| 137 |
+
context={"request": request, "path": request.url.path},
|
| 138 |
+
status_code=404,
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
# ------------------------------------------------------------------
|
| 142 |
+
# Startup
|
| 143 |
+
# ------------------------------------------------------------------
|
| 144 |
+
@app.on_event("startup")
|
| 145 |
+
async def startup_event():
|
| 146 |
+
mode_label = "🌍 PUBLIC (WordGame)" if settings.is_public else "🔒 PRIVATE (Lingo)"
|
| 147 |
+
print(f"🎮 {settings.APP_NAME} – {mode_label} mód elindult!")
|
| 148 |
+
print(f"📍 Szerver: http://{settings.HOST}:{settings.PORT}")
|
| 149 |
+
print(f"🔗 Public base: {settings.PUBLIC_BASE_URL}")
|
| 150 |
+
print(f"🔗 Private base: {settings.PRIVATE_BASE_URL}")
|
| 151 |
+
|
| 152 |
+
return app
|
src/wordgame/core/auth.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Központi autentikációs utility a public és private appokhoz.
|
| 2 |
+
|
| 3 |
+
Ez a modul biztosítja, hogy a public (WordGame) és private (Lingo) HF Space-ek
|
| 4 |
+
között egységesen működjön a felhasználó azonosítása a Supabase JWT
|
| 5 |
+
token-eken keresztül. Mivel a két Space más-más domain alatt fut
|
| 6 |
+
(humut-WordGame.hf.space vs humut-Lingo.hf.space), a cookie-k natívan
|
| 7 |
+
nem oszthatók meg – ehelyett a cross-domain SSO callback (Lingo
|
| 8 |
+
/auth/sso) hidat épít a kettő közé.
|
| 9 |
+
"""
|
| 10 |
+
from typing import Optional
|
| 11 |
+
|
| 12 |
+
from fastapi import Cookie, HTTPException, status, Response
|
| 13 |
+
|
| 14 |
+
from .database import supabase
|
| 15 |
+
from .config import settings
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# A cookie neve, amit mindenütt használunk.
|
| 19 |
+
ACCESS_TOKEN_COOKIE = "access_token"
|
| 20 |
+
|
| 21 |
+
# A rejtett admin email-ek – a production rollout során érdemes
|
| 22 |
+
# ezt a settings.ADMIN_EMAILS-be áthelyezni (env-ből tölteni).
|
| 23 |
+
ADMIN_EMAILS = {"adminn@wordgame.hu", "admin@wordgame.com"}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# ---------------------------------------------------------------------------
|
| 27 |
+
# Dependency-k
|
| 28 |
+
# ---------------------------------------------------------------------------
|
| 29 |
+
|
| 30 |
+
async def get_user_optional(
|
| 31 |
+
access_token: Optional[str] = Cookie(default=None, alias=ACCESS_TOKEN_COOKIE)
|
| 32 |
+
):
|
| 33 |
+
"""Visszaadja a Supabase user objektumot, ha van érvényes cookie.
|
| 34 |
+
|
| 35 |
+
Publikus route-okhoz való, ahol a user lehet belépve vagy sem.
|
| 36 |
+
Soha nem dob kivételt – ha bármi baj van, egyszerűen None-t ad vissza,
|
| 37 |
+
és a route eldönti, hogy ez mit jelent (pl. login gomb mutatása).
|
| 38 |
+
"""
|
| 39 |
+
if not access_token:
|
| 40 |
+
return None
|
| 41 |
+
try:
|
| 42 |
+
res = supabase.auth.get_user(access_token)
|
| 43 |
+
return res.user if res and res.user else None
|
| 44 |
+
except Exception:
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
async def require_user(
|
| 49 |
+
access_token: Optional[str] = Cookie(default=None, alias=ACCESS_TOKEN_COOKIE)
|
| 50 |
+
):
|
| 51 |
+
"""Kötelező bejelentkezés – 401-et dob, ha nincs érvényes session.
|
| 52 |
+
|
| 53 |
+
Privát route-okhoz (dashboard, szoba, deck, invite) való.
|
| 54 |
+
A kapott felhasználót a `profilok` táblában is ellenőrzi, hogy
|
| 55 |
+
a profil létezik-e (a Supabase auth.users és a profilok tábla
|
| 56 |
+
közötti eltérés kezelésére).
|
| 57 |
+
"""
|
| 58 |
+
if not access_token:
|
| 59 |
+
raise HTTPException(
|
| 60 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 61 |
+
detail="Bejelentkezés szükséges",
|
| 62 |
+
)
|
| 63 |
+
try:
|
| 64 |
+
res = supabase.auth.get_user(access_token)
|
| 65 |
+
if not res or not res.user:
|
| 66 |
+
raise HTTPException(
|
| 67 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 68 |
+
detail="Érvénytelen munkamenet",
|
| 69 |
+
)
|
| 70 |
+
return res.user
|
| 71 |
+
except HTTPException:
|
| 72 |
+
raise
|
| 73 |
+
except Exception:
|
| 74 |
+
raise HTTPException(
|
| 75 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 76 |
+
detail="Érvénytelen munkamenet",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
async def require_admin(
|
| 81 |
+
access_token: Optional[str] = Cookie(default=None, alias=ACCESS_TOKEN_COOKIE)
|
| 82 |
+
):
|
| 83 |
+
"""Admin jogosultságot kér – 403-at dob, ha a user emailje nem admin.
|
| 84 |
+
|
| 85 |
+
A rejtett /a7d9f2e1b4c6 route-ok és műveletek védelmére való.
|
| 86 |
+
"""
|
| 87 |
+
user = await require_user(access_token)
|
| 88 |
+
if not user.email or user.email not in ADMIN_EMAILS:
|
| 89 |
+
raise HTTPException(
|
| 90 |
+
status_code=status.HTTP_403_FORBIDDEN,
|
| 91 |
+
detail="Admin jogosultság szükséges",
|
| 92 |
+
)
|
| 93 |
+
return user
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# ---------------------------------------------------------------------------
|
| 97 |
+
# Prémium státusz ellenőrzése
|
| 98 |
+
# ---------------------------------------------------------------------------
|
| 99 |
+
|
| 100 |
+
def is_premium(user_id: str) -> bool:
|
| 101 |
+
"""Megnézi a `profilok` táblából, hogy a user prémium-e.
|
| 102 |
+
|
| 103 |
+
A függvény szinkron, mert a supabase-py kliens execute() hívása is szinkron
|
| 104 |
+
(asyncio wrapper nélkül). Ha hiba van, False-szal tér vissza – a route
|
| 105 |
+
dönti el, hogy ez elfogadható-e (pl. szobacsatlakozásnál igen, fizetésnél nem).
|
| 106 |
+
"""
|
| 107 |
+
try:
|
| 108 |
+
profile = supabase.table(settings.TABLE_PROFILES)\
|
| 109 |
+
.select("is_premium")\
|
| 110 |
+
.eq("id", user_id)\
|
| 111 |
+
.execute()
|
| 112 |
+
if profile.data and len(profile.data) > 0:
|
| 113 |
+
return bool(profile.data[0].get("is_premium", False))
|
| 114 |
+
except Exception:
|
| 115 |
+
pass
|
| 116 |
+
return False
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# ---------------------------------------------------------------------------
|
| 120 |
+
# Cookie beállítás / törlés helper-ek
|
| 121 |
+
# ---------------------------------------------------------------------------
|
| 122 |
+
|
| 123 |
+
def set_access_cookie(
|
| 124 |
+
response: Response,
|
| 125 |
+
token: str,
|
| 126 |
+
max_age: int = 3600,
|
| 127 |
+
) -> None:
|
| 128 |
+
"""Beállítja az access_token cookie-t a Response objektumon.
|
| 129 |
+
|
| 130 |
+
A cookie paraméterei környezetfüggőek:
|
| 131 |
+
- production (DEBUG=False): secure=True, samesite="none" (mert a
|
| 132 |
+
private Lingo Space cross-domain cookie-t fogad a public WordGame
|
| 133 |
+
Space SSO callback-jén keresztül)
|
| 134 |
+
- development (DEBUG=True): secure=False, samesite="lax" (hogy a
|
| 135 |
+
böngésző local fejlesztésnél is elfogadja)
|
| 136 |
+
"""
|
| 137 |
+
is_prod = not settings.DEBUG
|
| 138 |
+
response.set_cookie(
|
| 139 |
+
key=ACCESS_TOKEN_COOKIE,
|
| 140 |
+
value=token,
|
| 141 |
+
httponly=True,
|
| 142 |
+
secure=is_prod,
|
| 143 |
+
samesite="none" if is_prod else "lax",
|
| 144 |
+
max_age=max_age,
|
| 145 |
+
expires=max_age,
|
| 146 |
+
domain=None, # a saját (HF Space) domainre szól
|
| 147 |
+
path="/",
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def clear_access_cookie(response: Response) -> None:
|
| 152 |
+
"""Törli az access_token cookie-t (logout-hoz)."""
|
| 153 |
+
is_prod = not settings.DEBUG
|
| 154 |
+
response.delete_cookie(
|
| 155 |
+
key=ACCESS_TOKEN_COOKIE,
|
| 156 |
+
path="/",
|
| 157 |
+
secure=is_prod,
|
| 158 |
+
samesite="none" if is_prod else "lax",
|
| 159 |
+
domain=None,
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
# ---------------------------------------------------------------------------
|
| 164 |
+
# Backward-compat alias-ok
|
| 165 |
+
# ---------------------------------------------------------------------------
|
| 166 |
+
# A régi route-ok (game_routes, dashboard_routes, room_routes, admin_routes)
|
| 167 |
+
# különböző neveken hivatkoztak a saját auth helper-jeikre. Ezek az alias-ok
|
| 168 |
+
# megkönnyítik a fokozatos átállást, de a terv szerint a route-okat a későbbi
|
| 169 |
+
# lépésekben átírjuk, hogy közvetlenül a fenti függvényeket hívják.
|
| 170 |
+
|
| 171 |
+
get_current_user = get_user_optional # game_routes régi neve
|
src/wordgame/core/config.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
-
"""Application configuration management.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
from typing import Optional
|
| 4 |
from pydantic_settings import BaseSettings
|
|
@@ -7,29 +12,75 @@ from pydantic import Field
|
|
| 7 |
|
| 8 |
class Settings(BaseSettings):
|
| 9 |
"""Application settings loaded from environment variables."""
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Application
|
|
|
|
| 12 |
APP_NAME: str = "Szó-Kavalkád"
|
| 13 |
DEBUG: bool = False
|
| 14 |
API_PREFIX: str = "/api"
|
| 15 |
-
|
|
|
|
| 16 |
# Server
|
|
|
|
| 17 |
HOST: str = "127.0.0.1"
|
| 18 |
PORT: int = 8030
|
| 19 |
-
|
| 20 |
-
#
|
|
|
|
|
|
|
| 21 |
SUPABASE_URL: str = ""
|
| 22 |
SUPABASE_KEY: str = ""
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Security
|
|
|
|
| 25 |
SECRET_KEY: Optional[str] = None
|
| 26 |
ALGORITHM: str = "HS256"
|
| 27 |
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# CORS
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
TABLE_WORDS: str = "szavak"
|
| 34 |
TABLE_ROOMS: str = "szobak"
|
| 35 |
TABLE_ROOM_MEMBERS: str = "szoba_tagok"
|
|
@@ -39,20 +90,40 @@ class Settings(BaseSettings):
|
|
| 39 |
TABLE_DECKS: str = "paklik"
|
| 40 |
TABLE_DECK_WORDS: str = "pakli_szavak"
|
| 41 |
TABLE_INVITES: str = "meghivok"
|
| 42 |
-
|
|
|
|
| 43 |
# External APIs
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
PADDLE_VENDOR_ID: str = ""
|
| 48 |
PADDLE_API_KEY: str = ""
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
model_config = {
|
| 51 |
"env_file": ".env",
|
| 52 |
"case_sensitive": True,
|
| 53 |
-
"extra": "ignore"
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
settings = Settings()
|
|
|
|
| 1 |
+
"""Application configuration management.
|
| 2 |
+
|
| 3 |
+
A config betölti az összes környezeti változót (HF Space env, .env file).
|
| 4 |
+
Az `APP_MODE` változó határozza meg, hogy a jelenlegi instance a
|
| 5 |
+
public (WordGame) vagy a private (Lingo) appot indítja-e.
|
| 6 |
+
"""
|
| 7 |
import os
|
| 8 |
from typing import Optional
|
| 9 |
from pydantic_settings import BaseSettings
|
|
|
|
| 12 |
|
| 13 |
class Settings(BaseSettings):
|
| 14 |
"""Application settings loaded from environment variables."""
|
| 15 |
+
|
| 16 |
+
# ------------------------------------------------------------------
|
| 17 |
+
# App mode – eldönti, hogy public vagy private app indul
|
| 18 |
+
# ------------------------------------------------------------------
|
| 19 |
+
APP_MODE: str = Field(
|
| 20 |
+
default="public",
|
| 21 |
+
description="public = WordGame (játék), private = Lingo (dashboard)",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# ------------------------------------------------------------------
|
| 25 |
# Application
|
| 26 |
+
# ------------------------------------------------------------------
|
| 27 |
APP_NAME: str = "Szó-Kavalkád"
|
| 28 |
DEBUG: bool = False
|
| 29 |
API_PREFIX: str = "/api"
|
| 30 |
+
|
| 31 |
+
# ------------------------------------------------------------------
|
| 32 |
# Server
|
| 33 |
+
# ------------------------------------------------------------------
|
| 34 |
HOST: str = "127.0.0.1"
|
| 35 |
PORT: int = 8030
|
| 36 |
+
|
| 37 |
+
# ------------------------------------------------------------------
|
| 38 |
+
# Supabase – mindkét Space ugyanazt a Supabase projektet használja
|
| 39 |
+
# ------------------------------------------------------------------
|
| 40 |
SUPABASE_URL: str = ""
|
| 41 |
SUPABASE_KEY: str = ""
|
| 42 |
+
|
| 43 |
+
# ------------------------------------------------------------------
|
| 44 |
+
# Cross-domain SSO
|
| 45 |
+
# ------------------------------------------------------------------
|
| 46 |
+
# A public (WordGame) Space base URL-je – a private Lingo Space
|
| 47 |
+
# ebből tudja, hova kell visszairányítani a felhasználót az SSO
|
| 48 |
+
# callback után.
|
| 49 |
+
PUBLIC_BASE_URL: str = "https://humut-WordGame.hf.space"
|
| 50 |
+
# A private (Lingo) Space base URL-je – a public WordGame base.html
|
| 51 |
+
# ebből tudja, hova küldje a felhasználót a "Dashboard" gombra kattintva.
|
| 52 |
+
PRIVATE_BASE_URL: str = "https://humut-Lingo.hf.space"
|
| 53 |
+
# A Lingo Space rejtett admin URL prefixe
|
| 54 |
+
ADMIN_PATH: str = "a7d9f2e1b4c6"
|
| 55 |
+
|
| 56 |
+
# ------------------------------------------------------------------
|
| 57 |
# Security
|
| 58 |
+
# ------------------------------------------------------------------
|
| 59 |
SECRET_KEY: Optional[str] = None
|
| 60 |
ALGORITHM: str = "HS256"
|
| 61 |
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60
|
| 62 |
+
# Paddle webhook secret – az aláírás ellenőrzéséhez.
|
| 63 |
+
# A .env.example-ban PADDLE_WEBHOOK_SECRET néven szerepel.
|
| 64 |
+
PADDLE_WEBHOOK_SECRET: str = ""
|
| 65 |
+
|
| 66 |
+
# ------------------------------------------------------------------
|
| 67 |
# CORS
|
| 68 |
+
# ------------------------------------------------------------------
|
| 69 |
+
# Alapértelmezetten csak a másik HF Space-et engedélyezzük, plusz
|
| 70 |
+
# localhost a dev-hez. A termelési környezetben ezt felül kell
|
| 71 |
+
# írni a HF Space "Variables" szekciójában.
|
| 72 |
+
ALLOWED_ORIGINS: list[str] = Field(
|
| 73 |
+
default_factory=lambda: [
|
| 74 |
+
"https://humut-WordGame.hf.space",
|
| 75 |
+
"https://humut-Lingo.hf.space",
|
| 76 |
+
"http://localhost:8030",
|
| 77 |
+
"http://127.0.0.1:8030",
|
| 78 |
+
]
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
# ------------------------------------------------------------------
|
| 82 |
+
# Database tables (magyar nevek a Supabase sémában)
|
| 83 |
+
# ------------------------------------------------------------------
|
| 84 |
TABLE_WORDS: str = "szavak"
|
| 85 |
TABLE_ROOMS: str = "szobak"
|
| 86 |
TABLE_ROOM_MEMBERS: str = "szoba_tagok"
|
|
|
|
| 90 |
TABLE_DECKS: str = "paklik"
|
| 91 |
TABLE_DECK_WORDS: str = "pakli_szavak"
|
| 92 |
TABLE_INVITES: str = "meghivok"
|
| 93 |
+
|
| 94 |
+
# ------------------------------------------------------------------
|
| 95 |
# External APIs
|
| 96 |
+
# ------------------------------------------------------------------
|
| 97 |
+
SLANG_WORDS_URL: str = (
|
| 98 |
+
"https://raw.githubusercontent.com/Ashpex/Slang-Word/"
|
| 99 |
+
"refs/heads/master/slang.txt"
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# ------------------------------------------------------------------
|
| 103 |
+
# Payment (optional) – stringek, hogy az üres .env értékek is menjenek
|
| 104 |
+
# ------------------------------------------------------------------
|
| 105 |
PADDLE_VENDOR_ID: str = ""
|
| 106 |
PADDLE_API_KEY: str = ""
|
| 107 |
+
|
| 108 |
+
# ------------------------------------------------------------------
|
| 109 |
+
# Helpers
|
| 110 |
+
# ------------------------------------------------------------------
|
| 111 |
+
@property
|
| 112 |
+
def is_public(self) -> bool:
|
| 113 |
+
"""True, ha ez az instance a public WordGame appot futtatja."""
|
| 114 |
+
return self.APP_MODE.lower() == "public"
|
| 115 |
+
|
| 116 |
+
@property
|
| 117 |
+
def is_private(self) -> bool:
|
| 118 |
+
"""True, ha ez az instance a private Lingo appot futtatja."""
|
| 119 |
+
return self.APP_MODE.lower() == "private"
|
| 120 |
+
|
| 121 |
model_config = {
|
| 122 |
"env_file": ".env",
|
| 123 |
"case_sensitive": True,
|
| 124 |
+
"extra": "ignore",
|
| 125 |
}
|
| 126 |
|
| 127 |
|
| 128 |
+
# Globális settings instance – az alkalmazás többi része ezt importálja.
|
| 129 |
+
settings = Settings()
|
src/wordgame/main.py
DELETED
|
@@ -1,91 +0,0 @@
|
|
| 1 |
-
"""Main FastAPI application entry point."""
|
| 2 |
-
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
-
from fastapi.staticfiles import StaticFiles
|
| 4 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
-
from starlette.templating import Jinja2Templates
|
| 6 |
-
from starlette.responses import RedirectResponse, HTMLResponse
|
| 7 |
-
|
| 8 |
-
from .api import create_router
|
| 9 |
-
from .core.config import settings
|
| 10 |
-
|
| 11 |
-
import os
|
| 12 |
-
|
| 13 |
-
# Get the directory containing this file (src/wordgame)
|
| 14 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
-
|
| 16 |
-
# Templates are in src/wordgame/templates/
|
| 17 |
-
templates_dir = os.path.join(current_dir, "templates")
|
| 18 |
-
os.makedirs(templates_dir, exist_ok=True)
|
| 19 |
-
|
| 20 |
-
# Static files are in src/static/
|
| 21 |
-
static_dir = os.path.join(os.path.dirname(current_dir), "static")
|
| 22 |
-
os.makedirs(static_dir, exist_ok=True)
|
| 23 |
-
|
| 24 |
-
# Initialize FastAPI app
|
| 25 |
-
app = FastAPI(
|
| 26 |
-
title=settings.APP_NAME,
|
| 27 |
-
debug=settings.DEBUG,
|
| 28 |
-
version="1.0.0"
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
# Configure CORS
|
| 32 |
-
app.add_middleware(
|
| 33 |
-
CORSMiddleware,
|
| 34 |
-
allow_origins=settings.ALLOWED_ORIGINS,
|
| 35 |
-
allow_credentials=True,
|
| 36 |
-
allow_methods=["*"],
|
| 37 |
-
allow_headers=["*"],
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
# Mount static files
|
| 41 |
-
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
| 42 |
-
|
| 43 |
-
# Initialize templates
|
| 44 |
-
templates = Jinja2Templates(directory=templates_dir)
|
| 45 |
-
|
| 46 |
-
# Include API routes
|
| 47 |
-
app.include_router(create_router(templates))
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
@app.get("/jatek-valaszto", response_class=HTMLResponse)
|
| 51 |
-
async def jatek_valaszto_page(request: Request):
|
| 52 |
-
"""Game selector page."""
|
| 53 |
-
return templates.TemplateResponse(
|
| 54 |
-
request=request,
|
| 55 |
-
name="jatek-valaszto.html",
|
| 56 |
-
context={"request": request}
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
@app.get("/dashboard", response_class=RedirectResponse)
|
| 60 |
-
async def dashboard_redirect():
|
| 61 |
-
"""Redirect dashboard to game selector."""
|
| 62 |
-
return "/jatek-valaszto"
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
@app.exception_handler(404)
|
| 66 |
-
async def custom_404_handler(request: Request, exc):
|
| 67 |
-
"""Custom 404 Not Found error page."""
|
| 68 |
-
return templates.TemplateResponse(
|
| 69 |
-
request=request,
|
| 70 |
-
name="404.html",
|
| 71 |
-
context={"request": request, "path": request.url.path},
|
| 72 |
-
status_code=404
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
@app.on_event("startup")
|
| 77 |
-
async def startup_event():
|
| 78 |
-
"""Run on application startup."""
|
| 79 |
-
print(f"🎮 {settings.APP_NAME} elindult!")
|
| 80 |
-
print(f"📍 Szerver: http://{settings.HOST}:{settings.PORT}")
|
| 81 |
-
print(f"🔗 API prefix: {settings.API_PREFIX}")
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
if __name__ == "__main__":
|
| 85 |
-
import uvicorn
|
| 86 |
-
uvicorn.run(
|
| 87 |
-
"src.wordgame.main:app",
|
| 88 |
-
host=settings.HOST,
|
| 89 |
-
port=settings.PORT,
|
| 90 |
-
reload=settings.DEBUG
|
| 91 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/wordgame/main_private.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Private (Lingo) FastAPI app entry point.
|
| 2 |
+
|
| 3 |
+
A `humut-Lingo.hf.space` HF Space ezt a fájlt indítja el
|
| 4 |
+
(`APP_MODE=private` env változóval). A route-ok: dashboard,
|
| 5 |
+
szobák, deck, invite, admin, paddle webhook, SSO callback.
|
| 6 |
+
"""
|
| 7 |
+
from .app_factory import create_app
|
| 8 |
+
from .core.config import settings
|
| 9 |
+
|
| 10 |
+
app = create_app()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
import uvicorn
|
| 15 |
+
uvicorn.run(
|
| 16 |
+
"src.wordgame.main_private:app",
|
| 17 |
+
host=settings.HOST,
|
| 18 |
+
port=settings.PORT,
|
| 19 |
+
reload=settings.DEBUG,
|
| 20 |
+
)
|
src/wordgame/main_public.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Public (WordGame) FastAPI app entry point.
|
| 2 |
+
|
| 3 |
+
A `humut-WordGame.hf.space` HF Space ezt a fájlt indítja el
|
| 4 |
+
(`APP_MODE=public` env változóval). A route-ok: játék, login,
|
| 5 |
+
register, ranglétra, premium – mindaz, ami publikus.
|
| 6 |
+
"""
|
| 7 |
+
from .app_factory import create_app
|
| 8 |
+
from .core.config import settings
|
| 9 |
+
|
| 10 |
+
app = create_app()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
import uvicorn
|
| 15 |
+
uvicorn.run(
|
| 16 |
+
"src.wordgame.main_public:app",
|
| 17 |
+
host=settings.HOST,
|
| 18 |
+
port=settings.PORT,
|
| 19 |
+
reload=settings.DEBUG,
|
| 20 |
+
)
|
src/wordgame/private/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Private app package – a Lingo (HF Space) app indul el ebben a módban.
|
| 2 |
+
|
| 3 |
+
A `humut-Lingo.hf.space` deployment a dashboard, szobák, deck-ek,
|
| 4 |
+
invite-ok, rejtett admin panelt és a Paddle fizetési webhookot
|
| 5 |
+
szolgálja ki. A public WordGame Space-ről a felhasználó SSO
|
| 6 |
+
callback-en keresztül (token URL paraméterben) ide érkezik meg.
|
| 7 |
+
"""
|
src/wordgame/{api → private}/routes/__init__.py
RENAMED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
-
"""
|
| 2 |
from . import (
|
| 3 |
-
|
| 4 |
-
auth_routes,
|
| 5 |
room_routes,
|
| 6 |
-
|
| 7 |
paddle_routes,
|
| 8 |
-
|
|
|
|
| 9 |
)
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
-
"
|
| 13 |
-
"auth_routes",
|
| 14 |
"room_routes",
|
| 15 |
-
"
|
| 16 |
"paddle_routes",
|
| 17 |
-
"
|
| 18 |
-
|
|
|
|
|
|
| 1 |
+
"""Private app route-jai (Lingo Space)."""
|
| 2 |
from . import (
|
| 3 |
+
dashboard_routes,
|
|
|
|
| 4 |
room_routes,
|
| 5 |
+
admin_routes,
|
| 6 |
paddle_routes,
|
| 7 |
+
slang_routes,
|
| 8 |
+
sso_callback,
|
| 9 |
)
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
+
"dashboard_routes",
|
|
|
|
| 13 |
"room_routes",
|
| 14 |
+
"admin_routes",
|
| 15 |
"paddle_routes",
|
| 16 |
+
"slang_routes",
|
| 17 |
+
"sso_callback",
|
| 18 |
+
]
|
src/wordgame/{api → private}/routes/admin_routes.py
RENAMED
|
@@ -1,62 +1,48 @@
|
|
| 1 |
-
"""Admin routes - hidden admin panel for word management.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
-
import hashlib
|
| 4 |
from datetime import datetime
|
|
|
|
| 5 |
from fastapi import APIRouter, Request, Cookie, HTTPException, Form
|
| 6 |
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 7 |
from starlette.templating import Jinja2Templates
|
| 8 |
|
| 9 |
from ...core.database import supabase
|
| 10 |
from ...core.config import settings
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 14 |
-
"""Create admin routes router.
|
| 15 |
-
|
| 16 |
-
Args:
|
| 17 |
-
templates: Jinja2 templates instance
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
Configured APIRouter
|
| 21 |
-
"""
|
| 22 |
router = APIRouter()
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
#
|
| 26 |
-
ADMIN_PATH =
|
| 27 |
-
|
| 28 |
-
# Helper function to check admin status
|
| 29 |
-
async def is_admin(access_token: str = Cookie(None)) -> bool:
|
| 30 |
-
"""Check if user is admin based on email."""
|
| 31 |
-
if not access_token:
|
| 32 |
-
return False
|
| 33 |
-
try:
|
| 34 |
-
user = supabase.auth.get_user(access_token)
|
| 35 |
-
if user and user.user:
|
| 36 |
-
# Check if email is admin email
|
| 37 |
-
admin_emails = ["adminn@wordgame.hu", "admin@wordgame.com"]
|
| 38 |
-
return user.user.email in admin_emails
|
| 39 |
-
except Exception:
|
| 40 |
-
pass
|
| 41 |
-
return False
|
| 42 |
-
|
| 43 |
@router.get(f"/{ADMIN_PATH}", response_class=HTMLResponse)
|
| 44 |
-
async def admin_panel(
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
-
|
| 55 |
# Get statistics - initialize defaults
|
| 56 |
user_count = 0
|
| 57 |
total_words = 0
|
| 58 |
recent_words = []
|
| 59 |
-
|
| 60 |
# Count users (safely)
|
| 61 |
try:
|
| 62 |
user_response = supabase.table("auth.users").select("id", count="exact").execute()
|
|
@@ -64,7 +50,7 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Admin stats error (users): {e}")
|
| 66 |
user_count = 0
|
| 67 |
-
|
| 68 |
# Count words (safely)
|
| 69 |
try:
|
| 70 |
word_response = supabase.table(settings.TABLE_WORDS).select("id", count="exact").execute()
|
|
@@ -72,7 +58,7 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 72 |
except Exception as e:
|
| 73 |
print(f"Admin stats error (words): {e}")
|
| 74 |
total_words = 0
|
| 75 |
-
|
| 76 |
# Get recent words (safely)
|
| 77 |
try:
|
| 78 |
recent_response = supabase.table(settings.TABLE_WORDS)\
|
|
@@ -84,7 +70,7 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 84 |
except Exception as e:
|
| 85 |
print(f"Admin stats error (recent): {e}")
|
| 86 |
recent_words = []
|
| 87 |
-
|
| 88 |
return templates.TemplateResponse(
|
| 89 |
request=request,
|
| 90 |
name="admin.html",
|
|
@@ -95,29 +81,36 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 95 |
"recent_words": recent_words
|
| 96 |
}
|
| 97 |
)
|
| 98 |
-
|
| 99 |
@router.post(f"/{ADMIN_PATH}/add-word", response_class=HTMLResponse)
|
| 100 |
async def add_word(
|
| 101 |
request: Request,
|
| 102 |
-
access_token: str = Cookie(None),
|
| 103 |
word: str = Form(...),
|
| 104 |
category: str = Form(...)
|
| 105 |
):
|
| 106 |
-
"""Add a new word to the database."""
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
word_upper = word.strip().upper()
|
| 112 |
-
|
| 113 |
try:
|
| 114 |
-
# Check if word already exists
|
| 115 |
existing = supabase.table(settings.TABLE_WORDS)\
|
| 116 |
.select("id")\
|
| 117 |
.eq("szo", word_upper)\
|
| 118 |
.execute()\
|
| 119 |
.data
|
| 120 |
-
|
| 121 |
if existing:
|
| 122 |
return HTMLResponse(
|
| 123 |
content=f"""
|
|
@@ -127,12 +120,11 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 127 |
""",
|
| 128 |
headers={"HX-Reswap": "outerHTML"}
|
| 129 |
)
|
| 130 |
-
|
| 131 |
-
# Add word
|
| 132 |
result = supabase.table(settings.TABLE_WORDS)\
|
| 133 |
.insert({"szo": word_upper, "kategoria": category})\
|
| 134 |
.execute()
|
| 135 |
-
|
| 136 |
if result.data:
|
| 137 |
return HTMLResponse(
|
| 138 |
content=f"""
|
|
@@ -160,20 +152,32 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 160 |
""",
|
| 161 |
headers={"HX-Reswap": "outerHTML"}
|
| 162 |
)
|
| 163 |
-
|
| 164 |
@router.delete(f"/{ADMIN_PATH}/delete-word/{{word_id}}", response_class=HTMLResponse)
|
| 165 |
-
async def delete_word(
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
try:
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
.delete()\
|
| 174 |
.eq("id", word_id)\
|
| 175 |
.execute()
|
| 176 |
-
|
| 177 |
return HTMLResponse(
|
| 178 |
content=f"""
|
| 179 |
<div class="p-4 bg-green-100 dark:bg-green-900/30 border border-green-500 rounded mb-4">
|
|
@@ -191,5 +195,5 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 191 |
""",
|
| 192 |
headers={"HX-Reswap": "outerHTML"}
|
| 193 |
)
|
| 194 |
-
|
| 195 |
-
return router
|
|
|
|
| 1 |
+
"""Admin routes - hidden admin panel for word management (Lingo Space).
|
| 2 |
+
|
| 3 |
+
A rejtett `/{ADMIN_PATH}` URL csak a `core.auth.require_admin`
|
| 4 |
+
dependency-n átesett felhasználóknak érhető el.
|
| 5 |
+
"""
|
| 6 |
import os
|
|
|
|
| 7 |
from datetime import datetime
|
| 8 |
+
from typing import Optional
|
| 9 |
from fastapi import APIRouter, Request, Cookie, HTTPException, Form
|
| 10 |
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 11 |
from starlette.templating import Jinja2Templates
|
| 12 |
|
| 13 |
from ...core.database import supabase
|
| 14 |
from ...core.config import settings
|
| 15 |
+
from ...core.auth import require_admin
|
| 16 |
|
| 17 |
|
| 18 |
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 19 |
+
"""Create admin routes router."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
router = APIRouter()
|
| 21 |
+
|
| 22 |
+
# A rejtett admin URL path-t a settings tárolja, így production-ben
|
| 23 |
+
# könnyen átállítható környezeti változóból.
|
| 24 |
+
ADMIN_PATH = settings.ADMIN_PATH
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
@router.get(f"/{ADMIN_PATH}", response_class=HTMLResponse)
|
| 27 |
+
async def admin_panel(
|
| 28 |
+
request: Request,
|
| 29 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 30 |
+
):
|
| 31 |
+
"""Admin panel - hidden URL, admin auth required."""
|
| 32 |
+
try:
|
| 33 |
+
await require_admin(access_token=access_token)
|
| 34 |
+
except HTTPException:
|
| 35 |
+
# Ha nincs jogosultság, irányítsuk a loginra
|
| 36 |
+
return RedirectResponse(
|
| 37 |
+
url=f"{settings.PRIVATE_BASE_URL}/auth/login-page",
|
| 38 |
+
status_code=303
|
| 39 |
)
|
| 40 |
+
|
| 41 |
# Get statistics - initialize defaults
|
| 42 |
user_count = 0
|
| 43 |
total_words = 0
|
| 44 |
recent_words = []
|
| 45 |
+
|
| 46 |
# Count users (safely)
|
| 47 |
try:
|
| 48 |
user_response = supabase.table("auth.users").select("id", count="exact").execute()
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
print(f"Admin stats error (users): {e}")
|
| 52 |
user_count = 0
|
| 53 |
+
|
| 54 |
# Count words (safely)
|
| 55 |
try:
|
| 56 |
word_response = supabase.table(settings.TABLE_WORDS).select("id", count="exact").execute()
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
print(f"Admin stats error (words): {e}")
|
| 60 |
total_words = 0
|
| 61 |
+
|
| 62 |
# Get recent words (safely)
|
| 63 |
try:
|
| 64 |
recent_response = supabase.table(settings.TABLE_WORDS)\
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
print(f"Admin stats error (recent): {e}")
|
| 72 |
recent_words = []
|
| 73 |
+
|
| 74 |
return templates.TemplateResponse(
|
| 75 |
request=request,
|
| 76 |
name="admin.html",
|
|
|
|
| 81 |
"recent_words": recent_words
|
| 82 |
}
|
| 83 |
)
|
| 84 |
+
|
| 85 |
@router.post(f"/{ADMIN_PATH}/add-word", response_class=HTMLResponse)
|
| 86 |
async def add_word(
|
| 87 |
request: Request,
|
| 88 |
+
access_token: Optional[str] = Cookie(default=None),
|
| 89 |
word: str = Form(...),
|
| 90 |
category: str = Form(...)
|
| 91 |
):
|
| 92 |
+
"""Add a new word to the database (admin only)."""
|
| 93 |
+
try:
|
| 94 |
+
await require_admin(access_token=access_token)
|
| 95 |
+
except HTTPException as e:
|
| 96 |
+
return HTMLResponse(
|
| 97 |
+
content=f"""
|
| 98 |
+
<div class="p-4 bg-red-100 dark:bg-red-900/30 border border-red-500 rounded mb-4">
|
| 99 |
+
<p class="text-red-800 dark:text-red-200">Hiba: {e.detail}</p>
|
| 100 |
+
</div>
|
| 101 |
+
""",
|
| 102 |
+
status_code=e.status_code
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
word_upper = word.strip().upper()
|
| 106 |
+
|
| 107 |
try:
|
|
|
|
| 108 |
existing = supabase.table(settings.TABLE_WORDS)\
|
| 109 |
.select("id")\
|
| 110 |
.eq("szo", word_upper)\
|
| 111 |
.execute()\
|
| 112 |
.data
|
| 113 |
+
|
| 114 |
if existing:
|
| 115 |
return HTMLResponse(
|
| 116 |
content=f"""
|
|
|
|
| 120 |
""",
|
| 121 |
headers={"HX-Reswap": "outerHTML"}
|
| 122 |
)
|
| 123 |
+
|
|
|
|
| 124 |
result = supabase.table(settings.TABLE_WORDS)\
|
| 125 |
.insert({"szo": word_upper, "kategoria": category})\
|
| 126 |
.execute()
|
| 127 |
+
|
| 128 |
if result.data:
|
| 129 |
return HTMLResponse(
|
| 130 |
content=f"""
|
|
|
|
| 152 |
""",
|
| 153 |
headers={"HX-Reswap": "outerHTML"}
|
| 154 |
)
|
| 155 |
+
|
| 156 |
@router.delete(f"/{ADMIN_PATH}/delete-word/{{word_id}}", response_class=HTMLResponse)
|
| 157 |
+
async def delete_word(
|
| 158 |
+
request: Request,
|
| 159 |
+
word_id: int,
|
| 160 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 161 |
+
):
|
| 162 |
+
"""Delete a word from the database (admin only)."""
|
| 163 |
try:
|
| 164 |
+
await require_admin(access_token=access_token)
|
| 165 |
+
except HTTPException as e:
|
| 166 |
+
return HTMLResponse(
|
| 167 |
+
content=f"""
|
| 168 |
+
<div class="p-4 bg-red-100 dark:bg-red-900/30 border border-red-500 rounded mb-4">
|
| 169 |
+
<p class="text-red-800 dark:text-red-200">Hiba: {e.detail}</p>
|
| 170 |
+
</div>
|
| 171 |
+
""",
|
| 172 |
+
status_code=e.status_code
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
try:
|
| 176 |
+
supabase.table(settings.TABLE_WORDS)\
|
| 177 |
.delete()\
|
| 178 |
.eq("id", word_id)\
|
| 179 |
.execute()
|
| 180 |
+
|
| 181 |
return HTMLResponse(
|
| 182 |
content=f"""
|
| 183 |
<div class="p-4 bg-green-100 dark:bg-green-900/30 border border-green-500 rounded mb-4">
|
|
|
|
| 195 |
""",
|
| 196 |
headers={"HX-Reswap": "outerHTML"}
|
| 197 |
)
|
| 198 |
+
|
| 199 |
+
return router
|
src/wordgame/{api → private}/routes/dashboard_routes.py
RENAMED
|
@@ -1,4 +1,10 @@
|
|
| 1 |
-
"""User dashboard routes - subscription, decks, invites.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import json
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
from typing import Optional
|
|
@@ -11,120 +17,104 @@ import string
|
|
| 11 |
|
| 12 |
from ...core.database import supabase
|
| 13 |
from ...core.config import settings
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 17 |
"""Create user dashboard routes router.
|
| 18 |
-
|
| 19 |
Args:
|
| 20 |
templates: Jinja2 templates instance
|
| 21 |
-
|
| 22 |
Returns:
|
| 23 |
Configured APIRouter
|
| 24 |
"""
|
| 25 |
router = APIRouter()
|
| 26 |
-
|
| 27 |
-
# === Helper Functions ===
|
| 28 |
-
|
| 29 |
-
async def get_user_id(access_token: str = Cookie(None)) -> str:
|
| 30 |
-
"""Extract user ID from access token cookie."""
|
| 31 |
-
if not access_token:
|
| 32 |
-
raise HTTPException(status_code=401, detail="Bejelentkezés szükséges")
|
| 33 |
-
|
| 34 |
-
try:
|
| 35 |
-
user = supabase.auth.get_user(access_token)
|
| 36 |
-
return str(user.user.id)
|
| 37 |
-
except Exception:
|
| 38 |
-
raise HTTPException(status_code=401, detail="Érvénytelen munkamenet")
|
| 39 |
-
|
| 40 |
-
def is_premium(user_id: str) -> bool:
|
| 41 |
-
"""Check if user has premium status."""
|
| 42 |
-
profile = supabase.table(settings.TABLE_PROFILES)\
|
| 43 |
-
.select("is_premium")\
|
| 44 |
-
.eq("id", user_id)\
|
| 45 |
-
.execute()
|
| 46 |
-
return profile.data[0].get("is_premium", False) if profile.data else False
|
| 47 |
-
|
| 48 |
-
def generate_secure_code(length: int = 12) -> str:
|
| 49 |
-
"""Generate cryptographically secure code."""
|
| 50 |
-
alphabet = string.ascii_letters + string.digits
|
| 51 |
-
return ''.join(secrets.choice(alphabet) for _ in range(length))
|
| 52 |
-
|
| 53 |
# === Pydantic Models ===
|
| 54 |
-
|
| 55 |
class DeckCreateRequest(BaseModel):
|
| 56 |
category: str = Field(..., description="Word category")
|
| 57 |
difficulty: str = Field(default="medium", description="Difficulty level")
|
| 58 |
word_count: int = Field(default=10, ge=5, le=50, description="Number of words")
|
| 59 |
-
|
| 60 |
class InviteCreateRequest(BaseModel):
|
| 61 |
room_id: Optional[str] = Field(None, description="Room ID")
|
| 62 |
expires_in_hours: int = Field(default=24, ge=1, le=168, description="Expiration hours")
|
| 63 |
max_uses: Optional[int] = Field(None, ge=1, le=100, description="Max uses")
|
| 64 |
-
|
| 65 |
# === Dashboard Pages ===
|
| 66 |
-
|
| 67 |
@router.get("", response_class=HTMLResponse)
|
| 68 |
-
async def dashboard_page(request: Request, access_token: str = Cookie(None)):
|
| 69 |
-
"""Main dashboard page."""
|
| 70 |
try:
|
| 71 |
-
|
| 72 |
except HTTPException:
|
| 73 |
-
return HTMLResponse(
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# === Subscription Endpoints ===
|
| 78 |
-
|
| 79 |
-
@router.get("/subscription", response_class=
|
| 80 |
-
async def get_subscription(access_token: str = Cookie(None)):
|
| 81 |
-
"""Get user's subscription status."""
|
| 82 |
try:
|
| 83 |
-
|
| 84 |
-
except HTTPException
|
| 85 |
-
return
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
"days_remaining": None
|
| 99 |
-
})
|
| 100 |
-
|
| 101 |
# === Deck Endpoints ===
|
| 102 |
-
|
| 103 |
@router.post("/deck", response_class=JSONResponse)
|
| 104 |
-
async def create_deck(
|
|
|
|
|
|
|
|
|
|
| 105 |
"""Create a new AI-generated deck."""
|
| 106 |
try:
|
| 107 |
-
|
|
|
|
| 108 |
except HTTPException as e:
|
| 109 |
-
return JSONResponse({"error": e.detail}, status_code=
|
| 110 |
-
|
| 111 |
try:
|
| 112 |
body = await request.json()
|
| 113 |
deck_req = DeckCreateRequest(**body)
|
| 114 |
except ValidationError as e:
|
| 115 |
return JSONResponse({"error": str(e)}, status_code=400)
|
| 116 |
-
|
| 117 |
# Check deck limit
|
| 118 |
deck_count = supabase.table(settings.TABLE_DECKS)\
|
| 119 |
.select("id", count="exact")\
|
| 120 |
.eq("user_id", user_id)\
|
| 121 |
.execute()\
|
| 122 |
.count
|
| 123 |
-
|
| 124 |
-
max_decks = 20 if
|
| 125 |
if deck_count >= max_decks:
|
| 126 |
-
return JSONResponse(
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
| 128 |
# Create deck
|
| 129 |
deck_name = f"{deck_req.category.upper()} {datetime.now().strftime('%m.%d')}"
|
| 130 |
deck = supabase.table(settings.TABLE_DECKS)\
|
|
@@ -133,96 +123,134 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 133 |
"nev": deck_name,
|
| 134 |
"kategoria": deck_req.category,
|
| 135 |
"nehezseg": deck_req.difficulty,
|
| 136 |
-
"letrehozva": datetime.
|
| 137 |
})\
|
| 138 |
.execute()
|
| 139 |
-
|
| 140 |
if not deck.data:
|
| 141 |
-
return JSONResponse(
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
| 143 |
deck_id = deck.data[0]["id"]
|
| 144 |
-
|
| 145 |
# Generate sample words
|
| 146 |
sample_words = {
|
| 147 |
"szleng": ["CRING", "BASED", "VIBES", "SUSZE", "FAKEP", "SLAYY", "YEETZ", "BRUHS", "OKAY", "LMAOO"],
|
| 148 |
"matek": ["PLUSZ", "MINUS", "OSZTO", "SZORO", "NÉGYZ", "GYÖKÖ", "TÖRT_", "TIZED", "EGÉSZ", "NULLA"],
|
| 149 |
"gamer": ["NOOB_", "PROFI", "GANK_", "LOOT_", "QUEST", "BOSS_", "SKILL", "LEVEL", "XP___", "DROP_"]
|
| 150 |
}
|
| 151 |
-
|
| 152 |
words = sample_words.get(deck_req.category, sample_words["szleng"])[:deck_req.word_count]
|
| 153 |
-
|
| 154 |
# Add words to deck
|
| 155 |
for word in words:
|
| 156 |
supabase.table(settings.TABLE_DECK_WORDS)\
|
| 157 |
.insert({"pakli_id": deck_id, "szo": word})\
|
| 158 |
.execute()
|
| 159 |
-
|
| 160 |
return JSONResponse({
|
| 161 |
"id": deck_id,
|
| 162 |
"name": deck_name,
|
| 163 |
"category": deck_req.category,
|
| 164 |
"word_count": len(words),
|
| 165 |
"words": words,
|
| 166 |
-
"created_at": datetime.
|
| 167 |
"difficulty": deck_req.difficulty
|
| 168 |
})
|
| 169 |
-
|
| 170 |
-
@router.get("/deck", response_class=
|
| 171 |
-
async def list_decks(access_token: str = Cookie(None)):
|
| 172 |
-
"""List all user's decks."""
|
| 173 |
try:
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
| 178 |
decks = supabase.table(settings.TABLE_DECKS)\
|
| 179 |
.select("*")\
|
| 180 |
.eq("user_id", user_id)\
|
| 181 |
.order("letrehozva", desc=True)\
|
| 182 |
.execute()\
|
| 183 |
.data or []
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
for deck in decks:
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
"
|
| 197 |
-
"
|
| 198 |
-
"
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
# === Invite Endpoints ===
|
| 208 |
-
|
| 209 |
@router.post("/invite", response_class=JSONResponse)
|
| 210 |
-
async def create_invite(
|
|
|
|
|
|
|
|
|
|
| 211 |
"""Create a new invite link."""
|
| 212 |
try:
|
| 213 |
-
|
|
|
|
| 214 |
except HTTPException as e:
|
| 215 |
-
return JSONResponse({"error": e.detail}, status_code=
|
| 216 |
-
|
| 217 |
try:
|
| 218 |
body = await request.json()
|
| 219 |
invite_req = InviteCreateRequest(**body)
|
| 220 |
except ValidationError as e:
|
| 221 |
return JSONResponse({"error": str(e)}, status_code=400)
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
| 226 |
invite = supabase.table(settings.TABLE_INVITES)\
|
| 227 |
.insert({
|
| 228 |
"kod": code,
|
|
@@ -231,93 +259,140 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 231 |
"lejart": expires_at.isoformat(),
|
| 232 |
"max_hasznalat": invite_req.max_uses,
|
| 233 |
"hasznalatok": 0,
|
| 234 |
-
"letrehozva": datetime.
|
| 235 |
})\
|
| 236 |
.execute()
|
| 237 |
-
|
| 238 |
if not invite.data:
|
| 239 |
-
return JSONResponse(
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
| 241 |
return JSONResponse({
|
| 242 |
"code": code,
|
| 243 |
-
"url": f"
|
| 244 |
"expires_at": expires_at.isoformat(),
|
| 245 |
"max_uses": invite_req.max_uses,
|
| 246 |
"uses_remaining": invite_req.max_uses
|
| 247 |
})
|
| 248 |
-
|
| 249 |
-
@router.get("/invite", response_class=
|
| 250 |
-
async def list_invites(access_token: str = Cookie(None)):
|
| 251 |
-
"""List all user's active invites."""
|
| 252 |
try:
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
invites = supabase.table(settings.TABLE_INVITES)\
|
| 258 |
.select("*")\
|
| 259 |
.eq("letrehozo_id", user_id)\
|
| 260 |
-
.gt("lejart",
|
| 261 |
.order("letrehozva", desc=True)\
|
| 262 |
.execute()\
|
| 263 |
.data or []
|
| 264 |
-
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
for invite in invites:
|
| 267 |
code = invite.get("kod", "")
|
| 268 |
max_uses = invite.get("max_hasznalat")
|
| 269 |
uses = invite.get("hasznalatok", 0)
|
| 270 |
-
|
|
|
|
| 271 |
try:
|
| 272 |
expires_at = datetime.fromisoformat(invite["lejart"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
except (ValueError, KeyError):
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
@router.get("/invite/{code}/validate", response_class=JSONResponse)
|
| 287 |
async def validate_invite(code: str):
|
| 288 |
-
"""Validate an invite code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
invite = supabase.table(settings.TABLE_INVITES)\
|
| 290 |
.select("*")\
|
| 291 |
.eq("kod", code)\
|
| 292 |
.execute()\
|
| 293 |
.data
|
| 294 |
-
|
| 295 |
if not invite:
|
| 296 |
return JSONResponse({"valid": False, "message": "A meghívó kód nem található"})
|
| 297 |
-
|
| 298 |
invite = invite[0]
|
| 299 |
-
|
| 300 |
# Check expiration
|
| 301 |
if invite.get("lejart"):
|
| 302 |
try:
|
| 303 |
expiry = datetime.fromisoformat(invite["lejart"])
|
| 304 |
-
if datetime.
|
| 305 |
return JSONResponse({"valid": False, "message": "A meghívó kód lejárt"})
|
| 306 |
except (ValueError, KeyError):
|
| 307 |
pass
|
| 308 |
-
|
| 309 |
# Check max uses
|
| 310 |
max_uses = invite.get("max_hasznalat")
|
| 311 |
uses = invite.get("hasznalatok", 0)
|
| 312 |
-
|
| 313 |
if max_uses and uses >= max_uses:
|
| 314 |
-
return JSONResponse(
|
| 315 |
-
|
|
|
|
|
|
|
| 316 |
return JSONResponse({
|
| 317 |
"valid": True,
|
| 318 |
"message": "A meghívó kód érvényes",
|
| 319 |
"room_info": {"room_id": invite.get("szoba_id")} if invite.get("szoba_id") else None,
|
| 320 |
"creator": invite.get("letrehozo_id", "")[:8] + "..."
|
| 321 |
})
|
| 322 |
-
|
| 323 |
-
return router
|
|
|
|
| 1 |
+
"""User dashboard routes - subscription, decks, invites (Lingo Space).
|
| 2 |
+
|
| 3 |
+
A private (Lingo) HF Space-en fut. Minden route hitelesített felhasználót
|
| 4 |
+
igényel – a `require_user` dependency-t használjuk. A lokális
|
| 5 |
+
`get_user_id` és `is_premium` helper-ek törölve, helyettük a
|
| 6 |
+
`core.auth` központi függvényei.
|
| 7 |
+
"""
|
| 8 |
import json
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
from typing import Optional
|
|
|
|
| 17 |
|
| 18 |
from ...core.database import supabase
|
| 19 |
from ...core.config import settings
|
| 20 |
+
from ...core.auth import require_user, is_premium as auth_is_premium
|
| 21 |
|
| 22 |
|
| 23 |
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 24 |
"""Create user dashboard routes router.
|
| 25 |
+
|
| 26 |
Args:
|
| 27 |
templates: Jinja2 templates instance
|
| 28 |
+
|
| 29 |
Returns:
|
| 30 |
Configured APIRouter
|
| 31 |
"""
|
| 32 |
router = APIRouter()
|
| 33 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# === Pydantic Models ===
|
| 35 |
+
|
| 36 |
class DeckCreateRequest(BaseModel):
|
| 37 |
category: str = Field(..., description="Word category")
|
| 38 |
difficulty: str = Field(default="medium", description="Difficulty level")
|
| 39 |
word_count: int = Field(default=10, ge=5, le=50, description="Number of words")
|
| 40 |
+
|
| 41 |
class InviteCreateRequest(BaseModel):
|
| 42 |
room_id: Optional[str] = Field(None, description="Room ID")
|
| 43 |
expires_in_hours: int = Field(default=24, ge=1, le=168, description="Expiration hours")
|
| 44 |
max_uses: Optional[int] = Field(None, ge=1, le=100, description="Max uses")
|
| 45 |
+
|
| 46 |
# === Dashboard Pages ===
|
| 47 |
+
|
| 48 |
@router.get("", response_class=HTMLResponse)
|
| 49 |
+
async def dashboard_page(request: Request, access_token: Optional[str] = Cookie(default=None)):
|
| 50 |
+
"""Main dashboard page (HTML)."""
|
| 51 |
try:
|
| 52 |
+
user = await require_user(access_token=access_token)
|
| 53 |
except HTTPException:
|
| 54 |
+
return HTMLResponse(
|
| 55 |
+
content="<div class='text-red-500 text-center p-4'>Bejelentkezés szükséges</div>"
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
return templates.TemplateResponse(
|
| 59 |
+
"dashboard.html",
|
| 60 |
+
{"request": request, "user_id": str(user.id), "user_email": user.email}
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
# === Subscription Endpoints ===
|
| 64 |
+
|
| 65 |
+
@router.get("/subscription", response_class=HTMLResponse)
|
| 66 |
+
async def get_subscription(access_token: Optional[str] = Cookie(default=None)):
|
| 67 |
+
"""Get user's subscription status (HTML fragment for HTMX)."""
|
| 68 |
try:
|
| 69 |
+
user = await require_user(access_token=access_token)
|
| 70 |
+
except HTTPException:
|
| 71 |
+
return HTMLResponse(
|
| 72 |
+
content='<span class="text-red-500 text-sm">Bejelentkezés szükséges</span>'
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
is_prem = auth_is_premium(str(user.id))
|
| 76 |
+
|
| 77 |
+
if is_prem:
|
| 78 |
+
html = '<span class="inline-flex items-center gap-2 px-3 py-1 bg-amber-900/40 border border-amber-500/30 rounded-full text-sm font-bold text-amber-400">👑 Prémium</span>'
|
| 79 |
+
else:
|
| 80 |
+
html = '<span class="inline-flex items-center gap-2 px-3 py-1 bg-gray-700/40 border border-gray-600/30 rounded-full text-sm text-gray-400">Ingyenes</span>'
|
| 81 |
+
|
| 82 |
+
return HTMLResponse(content=html)
|
| 83 |
+
|
|
|
|
|
|
|
|
|
|
| 84 |
# === Deck Endpoints ===
|
| 85 |
+
|
| 86 |
@router.post("/deck", response_class=JSONResponse)
|
| 87 |
+
async def create_deck(
|
| 88 |
+
request: Request,
|
| 89 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 90 |
+
):
|
| 91 |
"""Create a new AI-generated deck."""
|
| 92 |
try:
|
| 93 |
+
user = await require_user(access_token=access_token)
|
| 94 |
+
user_id = str(user.id)
|
| 95 |
except HTTPException as e:
|
| 96 |
+
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
| 97 |
+
|
| 98 |
try:
|
| 99 |
body = await request.json()
|
| 100 |
deck_req = DeckCreateRequest(**body)
|
| 101 |
except ValidationError as e:
|
| 102 |
return JSONResponse({"error": str(e)}, status_code=400)
|
| 103 |
+
|
| 104 |
# Check deck limit
|
| 105 |
deck_count = supabase.table(settings.TABLE_DECKS)\
|
| 106 |
.select("id", count="exact")\
|
| 107 |
.eq("user_id", user_id)\
|
| 108 |
.execute()\
|
| 109 |
.count
|
| 110 |
+
|
| 111 |
+
max_decks = 20 if auth_is_premium(user_id) else 3
|
| 112 |
if deck_count >= max_decks:
|
| 113 |
+
return JSONResponse(
|
| 114 |
+
{"error": "Elérted a paklik maximális számát"},
|
| 115 |
+
status_code=400
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
# Create deck
|
| 119 |
deck_name = f"{deck_req.category.upper()} {datetime.now().strftime('%m.%d')}"
|
| 120 |
deck = supabase.table(settings.TABLE_DECKS)\
|
|
|
|
| 123 |
"nev": deck_name,
|
| 124 |
"kategoria": deck_req.category,
|
| 125 |
"nehezseg": deck_req.difficulty,
|
| 126 |
+
"letrehozva": datetime.utcnow().isoformat()
|
| 127 |
})\
|
| 128 |
.execute()
|
| 129 |
+
|
| 130 |
if not deck.data:
|
| 131 |
+
return JSONResponse(
|
| 132 |
+
{"error": "Nem sikerült létrehozni a paklit"},
|
| 133 |
+
status_code=500
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
deck_id = deck.data[0]["id"]
|
| 137 |
+
|
| 138 |
# Generate sample words
|
| 139 |
sample_words = {
|
| 140 |
"szleng": ["CRING", "BASED", "VIBES", "SUSZE", "FAKEP", "SLAYY", "YEETZ", "BRUHS", "OKAY", "LMAOO"],
|
| 141 |
"matek": ["PLUSZ", "MINUS", "OSZTO", "SZORO", "NÉGYZ", "GYÖKÖ", "TÖRT_", "TIZED", "EGÉSZ", "NULLA"],
|
| 142 |
"gamer": ["NOOB_", "PROFI", "GANK_", "LOOT_", "QUEST", "BOSS_", "SKILL", "LEVEL", "XP___", "DROP_"]
|
| 143 |
}
|
| 144 |
+
|
| 145 |
words = sample_words.get(deck_req.category, sample_words["szleng"])[:deck_req.word_count]
|
| 146 |
+
|
| 147 |
# Add words to deck
|
| 148 |
for word in words:
|
| 149 |
supabase.table(settings.TABLE_DECK_WORDS)\
|
| 150 |
.insert({"pakli_id": deck_id, "szo": word})\
|
| 151 |
.execute()
|
| 152 |
+
|
| 153 |
return JSONResponse({
|
| 154 |
"id": deck_id,
|
| 155 |
"name": deck_name,
|
| 156 |
"category": deck_req.category,
|
| 157 |
"word_count": len(words),
|
| 158 |
"words": words,
|
| 159 |
+
"created_at": datetime.utcnow().isoformat(),
|
| 160 |
"difficulty": deck_req.difficulty
|
| 161 |
})
|
| 162 |
+
|
| 163 |
+
@router.get("/deck", response_class=HTMLResponse)
|
| 164 |
+
async def list_decks(access_token: Optional[str] = Cookie(default=None)):
|
| 165 |
+
"""List all user's decks (HTML fragment for HTMX)."""
|
| 166 |
try:
|
| 167 |
+
user = await require_user(access_token=access_token)
|
| 168 |
+
user_id = str(user.id)
|
| 169 |
+
except HTTPException:
|
| 170 |
+
return HTMLResponse(
|
| 171 |
+
content='<div class="text-red-500 text-sm p-3">Bejelentkezés szükséges</div>'
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
decks = supabase.table(settings.TABLE_DECKS)\
|
| 175 |
.select("*")\
|
| 176 |
.eq("user_id", user_id)\
|
| 177 |
.order("letrehozva", desc=True)\
|
| 178 |
.execute()\
|
| 179 |
.data or []
|
| 180 |
+
|
| 181 |
+
if not decks:
|
| 182 |
+
return HTMLResponse(
|
| 183 |
+
content='<div class="text-gray-500 text-center py-6 italic">Még nincsenek paklid. Hozz létre egyet!</div>'
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
# Batch-fetch all words for all decks (fixes N+1 query)
|
| 187 |
+
deck_ids = [d["id"] for d in decks]
|
| 188 |
+
all_words = supabase.table(settings.TABLE_DECK_WORDS)\
|
| 189 |
+
.select("pakli_id, szo")\
|
| 190 |
+
.in_("pakli_id", deck_ids)\
|
| 191 |
+
.execute()\
|
| 192 |
+
.data or []
|
| 193 |
+
|
| 194 |
+
# Group words by deck_id
|
| 195 |
+
words_by_deck = {}
|
| 196 |
+
for w in all_words:
|
| 197 |
+
dek_id = w["pakli_id"]
|
| 198 |
+
if dek_id not in words_by_deck:
|
| 199 |
+
words_by_deck[dek_id] = []
|
| 200 |
+
words_by_deck[dek_id].append(w["szo"])
|
| 201 |
+
|
| 202 |
+
html = '<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">'
|
| 203 |
for deck in decks:
|
| 204 |
+
deck_words = words_by_deck.get(deck["id"], [])
|
| 205 |
+
word_count = len(deck_words)
|
| 206 |
+
word_preview = ", ".join(deck_words[:5])
|
| 207 |
+
if len(deck_words) > 5:
|
| 208 |
+
word_preview += f" +{len(deck_words) - 5}"
|
| 209 |
+
|
| 210 |
+
difficulty_badge = {
|
| 211 |
+
"easy": "bg-green-900/30 border-green-500/30 text-green-400",
|
| 212 |
+
"medium": "bg-amber-900/30 border-amber-500/30 text-amber-400",
|
| 213 |
+
"hard": "bg-red-900/30 border-red-500/30 text-red-400",
|
| 214 |
+
}.get(deck.get("nehezseg", ""), "bg-gray-900/30 border-gray-600/30 text-gray-400")
|
| 215 |
+
|
| 216 |
+
html += f'''
|
| 217 |
+
<div class="bg-gray-900 border border-gray-800 rounded-lg p-4 hover:border-gray-700 transition-colors">
|
| 218 |
+
<div class="flex justify-between items-start mb-2">
|
| 219 |
+
<h3 class="font-bold text-white text-lg">{deck.get("nev", "Névtelen")}</h3>
|
| 220 |
+
<span class="text-xs px-2 py-0.5 rounded border {difficulty_badge}">{deck.get("nehezseg", "?")}</span>
|
| 221 |
+
</div>
|
| 222 |
+
<p class="text-xs text-gray-400 mb-1">Kategória: {deck.get("kategoria", "?")}</p>
|
| 223 |
+
<p class="text-xs text-gray-500 mb-2">{word_count} szó</p>
|
| 224 |
+
<p class="text-xs text-gray-600 truncate">{word_preview}</p>
|
| 225 |
+
</div>'''
|
| 226 |
+
|
| 227 |
+
html += '</div>'
|
| 228 |
+
return HTMLResponse(content=html)
|
| 229 |
+
|
| 230 |
# === Invite Endpoints ===
|
| 231 |
+
|
| 232 |
@router.post("/invite", response_class=JSONResponse)
|
| 233 |
+
async def create_invite(
|
| 234 |
+
request: Request,
|
| 235 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 236 |
+
):
|
| 237 |
"""Create a new invite link."""
|
| 238 |
try:
|
| 239 |
+
user = await require_user(access_token=access_token)
|
| 240 |
+
user_id = str(user.id)
|
| 241 |
except HTTPException as e:
|
| 242 |
+
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
| 243 |
+
|
| 244 |
try:
|
| 245 |
body = await request.json()
|
| 246 |
invite_req = InviteCreateRequest(**body)
|
| 247 |
except ValidationError as e:
|
| 248 |
return JSONResponse({"error": str(e)}, status_code=400)
|
| 249 |
+
|
| 250 |
+
alphabet = string.ascii_letters + string.digits
|
| 251 |
+
code = ''.join(secrets.choice(alphabet) for _ in range(12))
|
| 252 |
+
expires_at = datetime.utcnow() + timedelta(hours=invite_req.expires_in_hours)
|
| 253 |
+
|
| 254 |
invite = supabase.table(settings.TABLE_INVITES)\
|
| 255 |
.insert({
|
| 256 |
"kod": code,
|
|
|
|
| 259 |
"lejart": expires_at.isoformat(),
|
| 260 |
"max_hasznalat": invite_req.max_uses,
|
| 261 |
"hasznalatok": 0,
|
| 262 |
+
"letrehozva": datetime.utcnow().isoformat()
|
| 263 |
})\
|
| 264 |
.execute()
|
| 265 |
+
|
| 266 |
if not invite.data:
|
| 267 |
+
return JSONResponse(
|
| 268 |
+
{"error": "Nem sikerült létrehozni a meghívót"},
|
| 269 |
+
status_code=500
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
return JSONResponse({
|
| 273 |
"code": code,
|
| 274 |
+
"url": f"{settings.PRIVATE_BASE_URL}/invite/{code}",
|
| 275 |
"expires_at": expires_at.isoformat(),
|
| 276 |
"max_uses": invite_req.max_uses,
|
| 277 |
"uses_remaining": invite_req.max_uses
|
| 278 |
})
|
| 279 |
+
|
| 280 |
+
@router.get("/invite", response_class=HTMLResponse)
|
| 281 |
+
async def list_invites(access_token: Optional[str] = Cookie(default=None)):
|
| 282 |
+
"""List all user's active invites (HTML fragment for HTMX)."""
|
| 283 |
try:
|
| 284 |
+
user = await require_user(access_token=access_token)
|
| 285 |
+
user_id = str(user.id)
|
| 286 |
+
except HTTPException:
|
| 287 |
+
return HTMLResponse(
|
| 288 |
+
content='<div class="text-red-500 text-sm p-3">Bejelentkezés szükséges</div>'
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
now_iso = datetime.utcnow().isoformat()
|
| 292 |
invites = supabase.table(settings.TABLE_INVITES)\
|
| 293 |
.select("*")\
|
| 294 |
.eq("letrehozo_id", user_id)\
|
| 295 |
+
.gt("lejart", now_iso)\
|
| 296 |
.order("letrehozva", desc=True)\
|
| 297 |
.execute()\
|
| 298 |
.data or []
|
| 299 |
+
|
| 300 |
+
if not invites:
|
| 301 |
+
return HTMLResponse(
|
| 302 |
+
content='<div class="text-gray-500 text-center py-6 italic">Még nincsenek aktív meghívóid. Hozz létre egyet!</div>'
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
now = datetime.utcnow()
|
| 306 |
+
html = '<div class="flex flex-col gap-3">'
|
| 307 |
for invite in invites:
|
| 308 |
code = invite.get("kod", "")
|
| 309 |
max_uses = invite.get("max_hasznalat")
|
| 310 |
uses = invite.get("hasznalatok", 0)
|
| 311 |
+
uses_remaining = (max_uses - uses) if max_uses else None
|
| 312 |
+
|
| 313 |
try:
|
| 314 |
expires_at = datetime.fromisoformat(invite["lejart"])
|
| 315 |
+
remaining = expires_at - now
|
| 316 |
+
if remaining.total_seconds() > 3600:
|
| 317 |
+
time_left = f"{int(remaining.total_seconds() / 3600)} óra"
|
| 318 |
+
elif remaining.total_seconds() > 60:
|
| 319 |
+
time_left = f"{int(remaining.total_seconds() / 60)} perc"
|
| 320 |
+
else:
|
| 321 |
+
time_left = f"{int(remaining.total_seconds())} mp"
|
| 322 |
+
is_expired = remaining.total_seconds() <= 0
|
| 323 |
except (ValueError, KeyError):
|
| 324 |
+
time_left = "?"
|
| 325 |
+
is_expired = False
|
| 326 |
+
|
| 327 |
+
status_color = "text-red-400" if is_expired else "text-green-400"
|
| 328 |
+
status_text = "Lejárt" if is_expired else "Aktív"
|
| 329 |
+
|
| 330 |
+
html += f'''
|
| 331 |
+
<div class="bg-gray-900 border border-gray-800 rounded-lg p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3">
|
| 332 |
+
<div class="flex-1 min-w-0">
|
| 333 |
+
<div class="flex items-center gap-2 mb-1">
|
| 334 |
+
<span class="font-mono text-white font-bold text-sm truncate">{code}</span>
|
| 335 |
+
<span class="text-xs {status_color} font-bold">{status_text}</span>
|
| 336 |
+
</div>
|
| 337 |
+
<p class="text-xs text-gray-400">Lejár: {time_left} • Felhasználva: {uses}{f' / {max_uses}' if max_uses else ''}</p>
|
| 338 |
+
</div>
|
| 339 |
+
<div class="flex items-center gap-2 shrink-0">
|
| 340 |
+
<input type="text" readonly value="{settings.PRIVATE_BASE_URL}/invite/{code}"
|
| 341 |
+
class="text-xs bg-gray-800 border border-gray-700 rounded px-2 py-1 text-gray-300 w-40 truncate"
|
| 342 |
+
onclick="this.select()" />
|
| 343 |
+
<button onclick="navigator.clipboard.writeText('{settings.PRIVATE_BASE_URL}/invite/{code}')"
|
| 344 |
+
class="px-3 py-1 text-xs font-bold bg-blue-600 hover:bg-blue-500 text-white rounded transition-colors">
|
| 345 |
+
Másol
|
| 346 |
+
</button>
|
| 347 |
+
</div>
|
| 348 |
+
</div>'''
|
| 349 |
+
|
| 350 |
+
html += '</div>'
|
| 351 |
+
return HTMLResponse(content=html)
|
| 352 |
+
|
| 353 |
@router.get("/invite/{code}/validate", response_class=JSONResponse)
|
| 354 |
async def validate_invite(code: str):
|
| 355 |
+
"""Validate an invite code (PUBLIC – meghívottak nem bejelentkezve jönnek).
|
| 356 |
+
|
| 357 |
+
Ez az endpoint szándékosan nem kér bejelentkezést, mert a
|
| 358 |
+
meghívott felhasználó a validáláskor még nem biztos, hogy
|
| 359 |
+
be van jelentkezve a Lingo Space-en. A tényleges csatlakozás
|
| 360 |
+
a `/szoba/csatlakozas` route-on történik, ami már hitelesített.
|
| 361 |
+
"""
|
| 362 |
invite = supabase.table(settings.TABLE_INVITES)\
|
| 363 |
.select("*")\
|
| 364 |
.eq("kod", code)\
|
| 365 |
.execute()\
|
| 366 |
.data
|
| 367 |
+
|
| 368 |
if not invite:
|
| 369 |
return JSONResponse({"valid": False, "message": "A meghívó kód nem található"})
|
| 370 |
+
|
| 371 |
invite = invite[0]
|
| 372 |
+
|
| 373 |
# Check expiration
|
| 374 |
if invite.get("lejart"):
|
| 375 |
try:
|
| 376 |
expiry = datetime.fromisoformat(invite["lejart"])
|
| 377 |
+
if datetime.utcnow() > expiry:
|
| 378 |
return JSONResponse({"valid": False, "message": "A meghívó kód lejárt"})
|
| 379 |
except (ValueError, KeyError):
|
| 380 |
pass
|
| 381 |
+
|
| 382 |
# Check max uses
|
| 383 |
max_uses = invite.get("max_hasznalat")
|
| 384 |
uses = invite.get("hasznalatok", 0)
|
| 385 |
+
|
| 386 |
if max_uses and uses >= max_uses:
|
| 387 |
+
return JSONResponse(
|
| 388 |
+
{"valid": False, "message": "A meghívó kód felhasználásainak száma elérte a maximumot"}
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
return JSONResponse({
|
| 392 |
"valid": True,
|
| 393 |
"message": "A meghívó kód érvényes",
|
| 394 |
"room_info": {"room_id": invite.get("szoba_id")} if invite.get("szoba_id") else None,
|
| 395 |
"creator": invite.get("letrehozo_id", "")[:8] + "..."
|
| 396 |
})
|
| 397 |
+
|
| 398 |
+
return router
|
src/wordgame/private/routes/paddle_routes.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Paddle payment webhook routes (Lingo Space) – HMAC-SHA256 signature verification."""
|
| 2 |
+
import hmac
|
| 3 |
+
import hashlib
|
| 4 |
+
import json
|
| 5 |
+
import time
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
from typing import Optional
|
| 8 |
+
from fastapi import APIRouter, Request, Header, HTTPException
|
| 9 |
+
|
| 10 |
+
from ...core.database import supabase
|
| 11 |
+
from ...core.config import settings
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _verify_paddle_signature(
|
| 15 |
+
payload_raw: bytes,
|
| 16 |
+
paddle_signature: Optional[str],
|
| 17 |
+
) -> bool:
|
| 18 |
+
"""Paddle webhook aláírás ellenőrzése (HMAC-SHA256)."""
|
| 19 |
+
secret = settings.PADDLE_WEBHOOK_SECRET
|
| 20 |
+
if not secret:
|
| 21 |
+
if settings.DEBUG:
|
| 22 |
+
print("[WARN] PADDLE_WEBHOOK_SECRET nincs beállítva (DEBUG mód – átengedve)")
|
| 23 |
+
return True
|
| 24 |
+
return False
|
| 25 |
+
|
| 26 |
+
if not paddle_signature:
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
parts = dict(
|
| 30 |
+
segment.split("=", 1)
|
| 31 |
+
for segment in paddle_signature.split(";")
|
| 32 |
+
if "=" in segment
|
| 33 |
+
)
|
| 34 |
+
ts = parts.get("ts", "")
|
| 35 |
+
h1 = parts.get("h1", "")
|
| 36 |
+
|
| 37 |
+
if not ts or not h1:
|
| 38 |
+
return False
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
ts_int = int(ts)
|
| 42 |
+
if abs(time.time() - ts_int) > 300:
|
| 43 |
+
print(f"[WARN] Paddle webhook timestamp túl régi: {ts_int}")
|
| 44 |
+
return False
|
| 45 |
+
except ValueError:
|
| 46 |
+
return False
|
| 47 |
+
|
| 48 |
+
signed_payload = f"{ts}.".encode() + payload_raw
|
| 49 |
+
expected_h1 = hmac.new(
|
| 50 |
+
secret.encode(),
|
| 51 |
+
signed_payload,
|
| 52 |
+
hashlib.sha256,
|
| 53 |
+
).hexdigest()
|
| 54 |
+
|
| 55 |
+
return hmac.compare_digest(expected_h1, h1)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def create_router() -> APIRouter:
|
| 59 |
+
"""Create Paddle payment webhook routes router."""
|
| 60 |
+
router = APIRouter()
|
| 61 |
+
|
| 62 |
+
@router.post("/paddle-webhook")
|
| 63 |
+
async def paddle_webhook(
|
| 64 |
+
request: Request,
|
| 65 |
+
paddle_signature: Optional[str] = Header(default=None, alias="Paddle-Signature")
|
| 66 |
+
):
|
| 67 |
+
"""Handle Paddle payment webhooks (signature verified).
|
| 68 |
+
|
| 69 |
+
A webhook idempotens: ugyanazt a transaction_id-t csak egyszer
|
| 70 |
+
dolgozza fel, így a Paddle által küldött ismételt webhook-ok
|
| 71 |
+
nem okoznak duplikált prémium aktiválást.
|
| 72 |
+
"""
|
| 73 |
+
payload_raw = await request.body()
|
| 74 |
+
|
| 75 |
+
if not _verify_paddle_signature(payload_raw, paddle_signature):
|
| 76 |
+
raise HTTPException(
|
| 77 |
+
status_code=401,
|
| 78 |
+
detail="Érvénytelen Paddle aláírás"
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
try:
|
| 82 |
+
payload = json.loads(payload_raw)
|
| 83 |
+
except json.JSONDecodeError:
|
| 84 |
+
raise HTTPException(status_code=400, detail="Érvénytelen JSON payload")
|
| 85 |
+
|
| 86 |
+
event_type = payload.get("event_type")
|
| 87 |
+
|
| 88 |
+
if event_type == "transaction.completed":
|
| 89 |
+
data = payload.get("data", {})
|
| 90 |
+
transaction_id = data.get("id") or payload.get("transaction_id")
|
| 91 |
+
custom_data = data.get("custom_data") or {}
|
| 92 |
+
user_id = custom_data.get("user_id")
|
| 93 |
+
if user_id:
|
| 94 |
+
# Idempotencia ellenőrzés: ugyanazt a tranzakciót
|
| 95 |
+
# csak egyszer dolgozzuk fel
|
| 96 |
+
if transaction_id:
|
| 97 |
+
existing = supabase.table(settings.TABLE_SUBSCRIPTIONS)\
|
| 98 |
+
.select("id")\
|
| 99 |
+
.eq("transaction_id", str(transaction_id))\
|
| 100 |
+
.execute()\
|
| 101 |
+
.data
|
| 102 |
+
if existing:
|
| 103 |
+
print(f"[PADDLE] Már feldolgozott tranzakció: {transaction_id}")
|
| 104 |
+
return {"status": "already_processed"}
|
| 105 |
+
|
| 106 |
+
# Profil frissítése prémiumra
|
| 107 |
+
supabase.table(settings.TABLE_PROFILES)\
|
| 108 |
+
.update({"is_premium": True})\
|
| 109 |
+
.eq("id", user_id)\
|
| 110 |
+
.execute()
|
| 111 |
+
|
| 112 |
+
# Tranzakció rögzítése az ismétlés megelőzésére
|
| 113 |
+
if transaction_id:
|
| 114 |
+
supabase.table(settings.TABLE_SUBSCRIPTIONS)\
|
| 115 |
+
.insert({
|
| 116 |
+
"user_id": user_id,
|
| 117 |
+
"transaction_id": str(transaction_id),
|
| 118 |
+
"status": "completed",
|
| 119 |
+
"created_at": datetime.utcnow().isoformat(),
|
| 120 |
+
})\
|
| 121 |
+
.execute()
|
| 122 |
+
|
| 123 |
+
print(f"Felhasználó {user_id} sikeresen prémiumra váltott!")
|
| 124 |
+
|
| 125 |
+
return {"status": "success"}
|
| 126 |
+
|
| 127 |
+
return router
|
src/wordgame/{api → private}/routes/room_routes.py
RENAMED
|
@@ -1,58 +1,60 @@
|
|
| 1 |
-
"""Room routes - multiplayer room management.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import string
|
| 3 |
import random
|
| 4 |
-
from
|
|
|
|
| 5 |
from fastapi.responses import HTMLResponse
|
|
|
|
| 6 |
from ...core.database import supabase
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def create_router() -> APIRouter:
|
| 10 |
-
"""Create room management routes router.
|
| 11 |
-
|
| 12 |
-
Returns:
|
| 13 |
-
Configured APIRouter
|
| 14 |
-
"""
|
| 15 |
router = APIRouter()
|
| 16 |
-
|
| 17 |
def generate_room_code(length: int = 6) -> str:
|
| 18 |
"""Generate random room code."""
|
| 19 |
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
|
| 20 |
-
|
| 21 |
-
async def get_user_from_token(access_token: str) -> dict | None:
|
| 22 |
-
"""Extract user info from access token."""
|
| 23 |
-
if not access_token:
|
| 24 |
-
return None
|
| 25 |
-
try:
|
| 26 |
-
user_res = supabase.auth.get_user(access_token)
|
| 27 |
-
return {"id": str(user_res.user.id), "email": user_res.user.email}
|
| 28 |
-
except Exception:
|
| 29 |
-
return None
|
| 30 |
-
|
| 31 |
@router.post("/letrehozas", response_class=HTMLResponse)
|
| 32 |
-
async def letrehoz_szoba(
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return HTMLResponse(
|
| 37 |
content="<div class='text-red-500 font-bold text-center p-3 bg-red-950/30 border border-red-500/30 rounded'>HIBA: Bejelentkezés szükséges!</div>",
|
| 38 |
status_code=401
|
| 39 |
)
|
| 40 |
-
|
| 41 |
kod = generate_room_code()
|
| 42 |
-
szoba_data = {"tulajdonos_id":
|
| 43 |
-
szoba_res = supabase.table(
|
| 44 |
-
|
| 45 |
if not szoba_res.data:
|
| 46 |
return HTMLResponse(
|
| 47 |
content="<div class='text-red-500 font-bold text-center p-3 bg-red-950/30 border border-red-500/30 rounded'>HIBA: Adatbázis hiba történt!</div>",
|
| 48 |
status_code=500
|
| 49 |
)
|
| 50 |
-
|
| 51 |
szoba_id = szoba_res.data[0]["id"]
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
html_lobby = f"""
|
| 57 |
<div class="w-full max-w-md bg-gray-950 border border-gray-800 rounded-xl p-6 text-center shadow-xl animate-fade-in mx-auto">
|
| 58 |
<h3 class="text-xl font-black text-green-400 mb-2">VÁRÓTEREM (LOBBY)</h3>
|
|
@@ -63,73 +65,79 @@ def create_router() -> APIRouter:
|
|
| 63 |
<div class="text-left border-t border-gray-900 pt-4">
|
| 64 |
<h4 class="text-xs font-bold uppercase tracking-wider text-gray-500 mb-2">Csatlakozott tagok:</h4>
|
| 65 |
<div id="lobby-tagok" hx-get="/szoba/statusz/{szoba_id}" hx-trigger="every 3s" class="flex flex-col gap-2 text-sm text-gray-300">
|
| 66 |
-
<div class="p-2 bg-gray-900/50 rounded border border-gray-900 font-semibold text-green-400">👑 {
|
| 67 |
</div>
|
| 68 |
</div>
|
| 69 |
</div>
|
| 70 |
"""
|
| 71 |
return HTMLResponse(content=html_lobby)
|
| 72 |
-
|
| 73 |
@router.post("/csatlakozas", response_class=HTMLResponse)
|
| 74 |
-
async def csatlakozik_szoba(
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
return HTMLResponse(
|
| 79 |
content="<div class='text-red-500 font-bold text-center p-3 bg-red-950/30 border border-red-500/30 rounded'>HIBA: Bejelentkezés szükséges!</div>",
|
| 80 |
status_code=401
|
| 81 |
)
|
| 82 |
-
|
| 83 |
-
szoba_res = supabase.table(
|
| 84 |
.select("id", "tulajdonos_id")\
|
| 85 |
.eq("kod", szoba_kod.upper().strip())\
|
| 86 |
.execute()
|
| 87 |
-
|
| 88 |
if not szoba_res.data:
|
| 89 |
return HTMLResponse(
|
| 90 |
content="<div class='text-red-500 font-bold text-sm bg-red-950/30 p-3 rounded border border-red-500/30 text-center'>HIBA: A megadott szobakód nem létezik!</div>"
|
| 91 |
)
|
| 92 |
-
|
| 93 |
szoba = szoba_res.data[0]
|
| 94 |
szoba_id = szoba["id"]
|
| 95 |
tulajdonos_id = szoba["tulajdonos_id"]
|
| 96 |
-
|
| 97 |
-
tagok_count_res = supabase.table(
|
| 98 |
.select("id")\
|
| 99 |
.eq("szoba_id", szoba_id)\
|
| 100 |
.execute()
|
| 101 |
jelenlegi_tagok_szama = len(tagok_count_res.data) if tagok_count_res.data else 0
|
| 102 |
-
|
| 103 |
if jelenlegi_tagok_szama >= 4:
|
| 104 |
-
profil_res = supabase.table(
|
| 105 |
.select("is_premium")\
|
| 106 |
.eq("id", tulajdonos_id)\
|
| 107 |
.execute()
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
if not
|
| 111 |
return HTMLResponse(content="""
|
| 112 |
<div class="p-4 bg-amber-950/40 border border-amber-500/30 rounded text-center text-amber-400 text-sm w-full max-w-md mx-auto">
|
| 113 |
👑 A szoba elérte a maximum 4 fős limitet! 4-nél több játékos fogadásához a szoba létrehozójának <strong>Prémium</strong> tagsággal kell rendelkeznie.
|
| 114 |
</div>
|
| 115 |
""")
|
| 116 |
-
|
| 117 |
-
check_tag = supabase.table(
|
| 118 |
.select("id")\
|
| 119 |
.eq("szoba_id", szoba_id)\
|
| 120 |
-
.eq("user_id",
|
| 121 |
.execute()
|
| 122 |
-
|
| 123 |
if not check_tag.data:
|
| 124 |
-
supabase.table(
|
| 125 |
-
.insert({"szoba_id": szoba_id, "user_id":
|
| 126 |
.execute()
|
| 127 |
-
|
| 128 |
-
tagok_res = supabase.table(
|
| 129 |
.select("user_id")\
|
| 130 |
.eq("szoba_id", szoba_id)\
|
| 131 |
.execute()
|
| 132 |
-
|
| 133 |
html_lobby = f"""
|
| 134 |
<div class="w-full max-w-md bg-gray-950 border border-gray-800 rounded-xl p-6 text-center shadow-xl animate-fade-in mx-auto">
|
| 135 |
<h3 class="text-xl font-black text-green-400 mb-2">VÁRÓTEREM (LOBBY)</h3>
|
|
@@ -141,42 +149,53 @@ def create_router() -> APIRouter:
|
|
| 141 |
<h4 class="text-xs font-bold uppercase tracking-wider text-gray-500 mb-2">Csatlakozott tagok:</h4>
|
| 142 |
<div id="lobby-tagok" hx-get="/szoba/statusz/{szoba_id}" hx-trigger="every 3s" class="flex flex-col gap-2 text-sm text-gray-300">
|
| 143 |
"""
|
| 144 |
-
|
| 145 |
for t in tagok_res.data:
|
| 146 |
prefix = "👑 " if t["user_id"] == tulajdonos_id else "👤 "
|
| 147 |
color = "text-green-400 font-semibold" if t["user_id"] == tulajdonos_id else "text-gray-300"
|
| 148 |
html_lobby += f'<div class="p-2 bg-gray-900/50 rounded border border-gray-900 {color}">{prefix} {t["user_id"][:8]}...</div>'
|
| 149 |
-
|
| 150 |
html_lobby += """
|
| 151 |
</div>
|
| 152 |
</div>
|
| 153 |
</div>
|
| 154 |
"""
|
| 155 |
return HTMLResponse(content=html_lobby)
|
| 156 |
-
|
| 157 |
@router.get("/statusz/{szoba_id}", response_class=HTMLResponse)
|
| 158 |
-
async def szoba_statusz(
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
.select("tulajdonos_id")\
|
| 162 |
.eq("id", szoba_id)\
|
| 163 |
.execute()
|
| 164 |
-
|
| 165 |
if not szoba_res.data:
|
| 166 |
return HTMLResponse(content="Szoba nem létezik", status_code=404)
|
| 167 |
-
|
| 168 |
tulajdonos_id = szoba_res.data[0]["tulajdonos_id"]
|
| 169 |
-
tagok_res = supabase.table(
|
| 170 |
.select("user_id")\
|
| 171 |
.eq("szoba_id", szoba_id)\
|
| 172 |
.execute()
|
| 173 |
-
|
| 174 |
html_valasz = ""
|
| 175 |
for t in tagok_res.data:
|
| 176 |
prefix = "👑 " if t["user_id"] == tulajdonos_id else "👤 "
|
| 177 |
color = "text-green-400 font-semibold" if t["user_id"] == tulajdonos_id else "text-gray-300"
|
| 178 |
html_valasz += f'<div class="p-2 bg-gray-900/50 rounded border border-gray-900 {color}">{prefix} {t["user_id"][:8]}...</div>'
|
| 179 |
-
|
| 180 |
return HTMLResponse(content=html_valasz)
|
| 181 |
-
|
| 182 |
-
return router
|
|
|
|
| 1 |
+
"""Room routes - multiplayer room management (Lingo Space).
|
| 2 |
+
|
| 3 |
+
A private (Lingo) HF Space-en fut. A korábbi lokális `get_user_from_token`
|
| 4 |
+
helyett a `core.auth.require_user` dependency-t használjuk.
|
| 5 |
+
A `/szoba/statusz` route is hitelesítéshez kötve (korábban bárki
|
| 6 |
+
lekérdezhette, ami adatvédelmi kockázat volt).
|
| 7 |
+
"""
|
| 8 |
import string
|
| 9 |
import random
|
| 10 |
+
from typing import Optional
|
| 11 |
+
from fastapi import APIRouter, Request, Cookie, HTTPException, Form
|
| 12 |
from fastapi.responses import HTMLResponse
|
| 13 |
+
|
| 14 |
from ...core.database import supabase
|
| 15 |
+
from ...core.auth import require_user
|
| 16 |
+
from ...core.config import settings
|
| 17 |
|
| 18 |
|
| 19 |
def create_router() -> APIRouter:
|
| 20 |
+
"""Create room management routes router."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
router = APIRouter()
|
| 22 |
+
|
| 23 |
def generate_room_code(length: int = 6) -> str:
|
| 24 |
"""Generate random room code."""
|
| 25 |
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
|
| 26 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
@router.post("/letrehozas", response_class=HTMLResponse)
|
| 28 |
+
async def letrehoz_szoba(
|
| 29 |
+
request: Request,
|
| 30 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 31 |
+
):
|
| 32 |
+
"""Create new room (auth required)."""
|
| 33 |
+
try:
|
| 34 |
+
user = await require_user(access_token=access_token)
|
| 35 |
+
user_id = str(user.id)
|
| 36 |
+
except HTTPException:
|
| 37 |
return HTMLResponse(
|
| 38 |
content="<div class='text-red-500 font-bold text-center p-3 bg-red-950/30 border border-red-500/30 rounded'>HIBA: Bejelentkezés szükséges!</div>",
|
| 39 |
status_code=401
|
| 40 |
)
|
| 41 |
+
|
| 42 |
kod = generate_room_code()
|
| 43 |
+
szoba_data = {"tulajdonos_id": user_id, "kod": kod}
|
| 44 |
+
szoba_res = supabase.table(settings.TABLE_ROOMS).insert(szoba_data).execute()
|
| 45 |
+
|
| 46 |
if not szoba_res.data:
|
| 47 |
return HTMLResponse(
|
| 48 |
content="<div class='text-red-500 font-bold text-center p-3 bg-red-950/30 border border-red-500/30 rounded'>HIBA: Adatbázis hiba történt!</div>",
|
| 49 |
status_code=500
|
| 50 |
)
|
| 51 |
+
|
| 52 |
szoba_id = szoba_res.data[0]["id"]
|
| 53 |
+
|
| 54 |
+
supabase.table(settings.TABLE_ROOM_MEMBERS).insert(
|
| 55 |
+
{"szoba_id": szoba_id, "user_id": user_id}
|
| 56 |
+
).execute()
|
| 57 |
+
|
| 58 |
html_lobby = f"""
|
| 59 |
<div class="w-full max-w-md bg-gray-950 border border-gray-800 rounded-xl p-6 text-center shadow-xl animate-fade-in mx-auto">
|
| 60 |
<h3 class="text-xl font-black text-green-400 mb-2">VÁRÓTEREM (LOBBY)</h3>
|
|
|
|
| 65 |
<div class="text-left border-t border-gray-900 pt-4">
|
| 66 |
<h4 class="text-xs font-bold uppercase tracking-wider text-gray-500 mb-2">Csatlakozott tagok:</h4>
|
| 67 |
<div id="lobby-tagok" hx-get="/szoba/statusz/{szoba_id}" hx-trigger="every 3s" class="flex flex-col gap-2 text-sm text-gray-300">
|
| 68 |
+
<div class="p-2 bg-gray-900/50 rounded border border-gray-900 font-semibold text-green-400">👑 {user_id[:8]}... (Tulajdonos)</div>
|
| 69 |
</div>
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
"""
|
| 73 |
return HTMLResponse(content=html_lobby)
|
| 74 |
+
|
| 75 |
@router.post("/csatlakozas", response_class=HTMLResponse)
|
| 76 |
+
async def csatlakozik_szoba(
|
| 77 |
+
request: Request,
|
| 78 |
+
szoba_kod: str = Form(...),
|
| 79 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 80 |
+
):
|
| 81 |
+
"""Join existing room (auth required)."""
|
| 82 |
+
try:
|
| 83 |
+
user = await require_user(access_token=access_token)
|
| 84 |
+
user_id = str(user.id)
|
| 85 |
+
except HTTPException:
|
| 86 |
return HTMLResponse(
|
| 87 |
content="<div class='text-red-500 font-bold text-center p-3 bg-red-950/30 border border-red-500/30 rounded'>HIBA: Bejelentkezés szükséges!</div>",
|
| 88 |
status_code=401
|
| 89 |
)
|
| 90 |
+
|
| 91 |
+
szoba_res = supabase.table(settings.TABLE_ROOMS)\
|
| 92 |
.select("id", "tulajdonos_id")\
|
| 93 |
.eq("kod", szoba_kod.upper().strip())\
|
| 94 |
.execute()
|
| 95 |
+
|
| 96 |
if not szoba_res.data:
|
| 97 |
return HTMLResponse(
|
| 98 |
content="<div class='text-red-500 font-bold text-sm bg-red-950/30 p-3 rounded border border-red-500/30 text-center'>HIBA: A megadott szobakód nem létezik!</div>"
|
| 99 |
)
|
| 100 |
+
|
| 101 |
szoba = szoba_res.data[0]
|
| 102 |
szoba_id = szoba["id"]
|
| 103 |
tulajdonos_id = szoba["tulajdonos_id"]
|
| 104 |
+
|
| 105 |
+
tagok_count_res = supabase.table(settings.TABLE_ROOM_MEMBERS)\
|
| 106 |
.select("id")\
|
| 107 |
.eq("szoba_id", szoba_id)\
|
| 108 |
.execute()
|
| 109 |
jelenlegi_tagok_szama = len(tagok_count_res.data) if tagok_count_res.data else 0
|
| 110 |
+
|
| 111 |
if jelenlegi_tagok_szama >= 4:
|
| 112 |
+
profil_res = supabase.table(settings.TABLE_PROFILES)\
|
| 113 |
.select("is_premium")\
|
| 114 |
.eq("id", tulajdonos_id)\
|
| 115 |
.execute()
|
| 116 |
+
is_premium_owner = profil_res.data[0].get("is_premium", False) if profil_res.data else False
|
| 117 |
+
|
| 118 |
+
if not is_premium_owner:
|
| 119 |
return HTMLResponse(content="""
|
| 120 |
<div class="p-4 bg-amber-950/40 border border-amber-500/30 rounded text-center text-amber-400 text-sm w-full max-w-md mx-auto">
|
| 121 |
👑 A szoba elérte a maximum 4 fős limitet! 4-nél több játékos fogadásához a szoba létrehozójának <strong>Prémium</strong> tagsággal kell rendelkeznie.
|
| 122 |
</div>
|
| 123 |
""")
|
| 124 |
+
|
| 125 |
+
check_tag = supabase.table(settings.TABLE_ROOM_MEMBERS)\
|
| 126 |
.select("id")\
|
| 127 |
.eq("szoba_id", szoba_id)\
|
| 128 |
+
.eq("user_id", user_id)\
|
| 129 |
.execute()
|
| 130 |
+
|
| 131 |
if not check_tag.data:
|
| 132 |
+
supabase.table(settings.TABLE_ROOM_MEMBERS)\
|
| 133 |
+
.insert({"szoba_id": szoba_id, "user_id": user_id})\
|
| 134 |
.execute()
|
| 135 |
+
|
| 136 |
+
tagok_res = supabase.table(settings.TABLE_ROOM_MEMBERS)\
|
| 137 |
.select("user_id")\
|
| 138 |
.eq("szoba_id", szoba_id)\
|
| 139 |
.execute()
|
| 140 |
+
|
| 141 |
html_lobby = f"""
|
| 142 |
<div class="w-full max-w-md bg-gray-950 border border-gray-800 rounded-xl p-6 text-center shadow-xl animate-fade-in mx-auto">
|
| 143 |
<h3 class="text-xl font-black text-green-400 mb-2">VÁRÓTEREM (LOBBY)</h3>
|
|
|
|
| 149 |
<h4 class="text-xs font-bold uppercase tracking-wider text-gray-500 mb-2">Csatlakozott tagok:</h4>
|
| 150 |
<div id="lobby-tagok" hx-get="/szoba/statusz/{szoba_id}" hx-trigger="every 3s" class="flex flex-col gap-2 text-sm text-gray-300">
|
| 151 |
"""
|
| 152 |
+
|
| 153 |
for t in tagok_res.data:
|
| 154 |
prefix = "👑 " if t["user_id"] == tulajdonos_id else "👤 "
|
| 155 |
color = "text-green-400 font-semibold" if t["user_id"] == tulajdonos_id else "text-gray-300"
|
| 156 |
html_lobby += f'<div class="p-2 bg-gray-900/50 rounded border border-gray-900 {color}">{prefix} {t["user_id"][:8]}...</div>'
|
| 157 |
+
|
| 158 |
html_lobby += """
|
| 159 |
</div>
|
| 160 |
</div>
|
| 161 |
</div>
|
| 162 |
"""
|
| 163 |
return HTMLResponse(content=html_lobby)
|
| 164 |
+
|
| 165 |
@router.get("/statusz/{szoba_id}", response_class=HTMLResponse)
|
| 166 |
+
async def szoba_statusz(
|
| 167 |
+
szoba_id: str,
|
| 168 |
+
access_token: Optional[str] = Cookie(default=None)
|
| 169 |
+
):
|
| 170 |
+
"""Get room status (HTMX polling, auth required)."""
|
| 171 |
+
try:
|
| 172 |
+
await require_user(access_token=access_token)
|
| 173 |
+
except HTTPException:
|
| 174 |
+
return HTMLResponse(
|
| 175 |
+
content="<div class='text-red-500 text-sm'>Nincs jogosultság</div>",
|
| 176 |
+
status_code=401
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
szoba_res = supabase.table(settings.TABLE_ROOMS)\
|
| 180 |
.select("tulajdonos_id")\
|
| 181 |
.eq("id", szoba_id)\
|
| 182 |
.execute()
|
| 183 |
+
|
| 184 |
if not szoba_res.data:
|
| 185 |
return HTMLResponse(content="Szoba nem létezik", status_code=404)
|
| 186 |
+
|
| 187 |
tulajdonos_id = szoba_res.data[0]["tulajdonos_id"]
|
| 188 |
+
tagok_res = supabase.table(settings.TABLE_ROOM_MEMBERS)\
|
| 189 |
.select("user_id")\
|
| 190 |
.eq("szoba_id", szoba_id)\
|
| 191 |
.execute()
|
| 192 |
+
|
| 193 |
html_valasz = ""
|
| 194 |
for t in tagok_res.data:
|
| 195 |
prefix = "👑 " if t["user_id"] == tulajdonos_id else "👤 "
|
| 196 |
color = "text-green-400 font-semibold" if t["user_id"] == tulajdonos_id else "text-gray-300"
|
| 197 |
html_valasz += f'<div class="p-2 bg-gray-900/50 rounded border border-gray-900 {color}">{prefix} {t["user_id"][:8]}...</div>'
|
| 198 |
+
|
| 199 |
return HTMLResponse(content=html_valasz)
|
| 200 |
+
|
| 201 |
+
return router
|
src/wordgame/{api → private}/routes/slang_routes.py
RENAMED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Slang word import routes."""
|
| 2 |
import httpx
|
| 3 |
from fastapi import APIRouter
|
| 4 |
from fastapi.responses import HTMLResponse
|
|
@@ -7,13 +7,9 @@ from ...core.config import settings
|
|
| 7 |
|
| 8 |
|
| 9 |
def create_router() -> APIRouter:
|
| 10 |
-
"""Create slang word import routes router.
|
| 11 |
-
|
| 12 |
-
Returns:
|
| 13 |
-
Configured APIRouter
|
| 14 |
-
"""
|
| 15 |
router = APIRouter()
|
| 16 |
-
|
| 17 |
@router.post("/szleng", response_class=HTMLResponse)
|
| 18 |
async def import_szleng_kifejezesek():
|
| 19 |
"""Import slang expressions from GitHub repository."""
|
|
@@ -26,10 +22,10 @@ def create_router() -> APIRouter:
|
|
| 26 |
content=f"<div class='text-red-500 font-bold p-3 bg-red-950/30 border border-red-500/30 rounded text-sm'>Letöltési hiba: {str(e)}</div>",
|
| 27 |
status_code=500
|
| 28 |
)
|
| 29 |
-
|
| 30 |
sorok = response.text.splitlines()
|
| 31 |
szurt_szavak = set()
|
| 32 |
-
|
| 33 |
for sor in sorok:
|
| 34 |
if not sor.strip():
|
| 35 |
continue
|
|
@@ -38,12 +34,12 @@ def create_router() -> APIRouter:
|
|
| 38 |
nyers_szo = reszek[0].strip().upper()
|
| 39 |
if len(nyers_szo) == 5 and nyers_szo.isalpha():
|
| 40 |
szurt_szavak.add(nyers_szo)
|
| 41 |
-
|
| 42 |
if not szurt_szavak:
|
| 43 |
return HTMLResponse(
|
| 44 |
content="<div class='text-amber-400 p-3 bg-amber-950/30 border border-amber-500/30 rounded text-sm'>Nem található megfelelő 5 betűs kifejezés.</div>"
|
| 45 |
)
|
| 46 |
-
|
| 47 |
sikeres = 0
|
| 48 |
for szo in szurt_szavak:
|
| 49 |
try:
|
|
@@ -53,11 +49,11 @@ def create_router() -> APIRouter:
|
|
| 53 |
sikeres += 1
|
| 54 |
except Exception:
|
| 55 |
continue
|
| 56 |
-
|
| 57 |
return HTMLResponse(content=f"""
|
| 58 |
<div class="p-4 bg-green-900/40 border border-green-500/30 rounded text-center text-green-400 text-sm">
|
| 59 |
🎉 Szinkronizáció kész! {sikeres} új egyedi szleng rögzítve a 'szavak' táblában.
|
| 60 |
</div>
|
| 61 |
""")
|
| 62 |
-
|
| 63 |
-
return router
|
|
|
|
| 1 |
+
"""Slang word import routes (Lingo Space)."""
|
| 2 |
import httpx
|
| 3 |
from fastapi import APIRouter
|
| 4 |
from fastapi.responses import HTMLResponse
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def create_router() -> APIRouter:
|
| 10 |
+
"""Create slang word import routes router."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
router = APIRouter()
|
| 12 |
+
|
| 13 |
@router.post("/szleng", response_class=HTMLResponse)
|
| 14 |
async def import_szleng_kifejezesek():
|
| 15 |
"""Import slang expressions from GitHub repository."""
|
|
|
|
| 22 |
content=f"<div class='text-red-500 font-bold p-3 bg-red-950/30 border border-red-500/30 rounded text-sm'>Letöltési hiba: {str(e)}</div>",
|
| 23 |
status_code=500
|
| 24 |
)
|
| 25 |
+
|
| 26 |
sorok = response.text.splitlines()
|
| 27 |
szurt_szavak = set()
|
| 28 |
+
|
| 29 |
for sor in sorok:
|
| 30 |
if not sor.strip():
|
| 31 |
continue
|
|
|
|
| 34 |
nyers_szo = reszek[0].strip().upper()
|
| 35 |
if len(nyers_szo) == 5 and nyers_szo.isalpha():
|
| 36 |
szurt_szavak.add(nyers_szo)
|
| 37 |
+
|
| 38 |
if not szurt_szavak:
|
| 39 |
return HTMLResponse(
|
| 40 |
content="<div class='text-amber-400 p-3 bg-amber-950/30 border border-amber-500/30 rounded text-sm'>Nem található megfelelő 5 betűs kifejezés.</div>"
|
| 41 |
)
|
| 42 |
+
|
| 43 |
sikeres = 0
|
| 44 |
for szo in szurt_szavak:
|
| 45 |
try:
|
|
|
|
| 49 |
sikeres += 1
|
| 50 |
except Exception:
|
| 51 |
continue
|
| 52 |
+
|
| 53 |
return HTMLResponse(content=f"""
|
| 54 |
<div class="p-4 bg-green-900/40 border border-green-500/30 rounded text-center text-green-400 text-sm">
|
| 55 |
🎉 Szinkronizáció kész! {sikeres} új egyedi szleng rögzítve a 'szavak' táblában.
|
| 56 |
</div>
|
| 57 |
""")
|
| 58 |
+
|
| 59 |
+
return router
|
src/wordgame/private/routes/sso_callback.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Cross-domain SSO callback endpoint (Lingo Space).
|
| 2 |
+
|
| 3 |
+
A public WordGame Space-ről a felhasználó a "Dashboard" gombra kattintva
|
| 4 |
+
átirányítódik ide a saját access_token-jével URL paraméterben:
|
| 5 |
+
|
| 6 |
+
https://humut-Lingo.hf.space/auth/sso?token=<ACCESS_TOKEN>&next=/dashboard
|
| 7 |
+
|
| 8 |
+
Ez az endpoint:
|
| 9 |
+
1. Ellenőrzi a token érvényességét a Supabase-en
|
| 10 |
+
2. Beállítja a Lingo Space saját cookie-ját (mert a HF Space-ek más-más
|
| 11 |
+
domain-ek, a cookie-k nem oszthatók meg natívan)
|
| 12 |
+
3. Átirányítja a felhasználót a `next` URL-re (alapértelmezetten `/dashboard`)
|
| 13 |
+
|
| 14 |
+
A biztonság kedvéért a `next` paraméter csak relatív útvonal lehet
|
| 15 |
+
(kezdődjön `/`-rel, de ne `//`-rel, ami protokoll-relatív URL-re utalna).
|
| 16 |
+
"""
|
| 17 |
+
from fastapi import APIRouter, Request, HTTPException
|
| 18 |
+
from fastapi.responses import RedirectResponse
|
| 19 |
+
from urllib.parse import quote, unquote
|
| 20 |
+
|
| 21 |
+
from ...core.database import supabase
|
| 22 |
+
from ...core.config import settings
|
| 23 |
+
from ...core.auth import set_access_cookie
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def create_router() -> APIRouter:
|
| 27 |
+
"""Create SSO callback router."""
|
| 28 |
+
router = APIRouter()
|
| 29 |
+
|
| 30 |
+
@router.get("/sso")
|
| 31 |
+
async def sso_callback(
|
| 32 |
+
request: Request,
|
| 33 |
+
token: str,
|
| 34 |
+
next: str = "/",
|
| 35 |
+
):
|
| 36 |
+
"""Cross-domain SSO callback.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
token: A public WordGame Space-ből átadott Supabase access_token
|
| 40 |
+
next: Relatív útvonal, ahova a user át lesz irányítva
|
| 41 |
+
|
| 42 |
+
Returns:
|
| 43 |
+
RedirectResponse a Lingo Space-en belülre, saját cookie-val
|
| 44 |
+
"""
|
| 45 |
+
# Biztonsági ellenőrzés: a `next` csak relatív útvonal lehet.
|
| 46 |
+
# Megakadályozza, hogy a user-t egy külső domain-re irányítsuk át
|
| 47 |
+
# (open redirect vulnerability).
|
| 48 |
+
if not next.startswith("/") or next.startswith("//"):
|
| 49 |
+
next = "/"
|
| 50 |
+
|
| 51 |
+
# Ellenőrizzük, hogy a token érvényes-e
|
| 52 |
+
try:
|
| 53 |
+
res = supabase.auth.get_user(token)
|
| 54 |
+
if not res or not res.user:
|
| 55 |
+
raise HTTPException(status_code=401, detail="Érvénytelen token")
|
| 56 |
+
except Exception as e:
|
| 57 |
+
raise HTTPException(
|
| 58 |
+
status_code=401,
|
| 59 |
+
detail=f"SSO authentication sikertelen: {str(e)}"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Beállítjuk a Lingo Space saját cookie-ját
|
| 63 |
+
response = RedirectResponse(
|
| 64 |
+
url=next,
|
| 65 |
+
status_code=303,
|
| 66 |
+
)
|
| 67 |
+
set_access_cookie(response, token, max_age=3600)
|
| 68 |
+
|
| 69 |
+
# Opcionális: a public base URL-re is visszamehetünk a
|
| 70 |
+
# biztonság kedvéért (hogy a user tudja, honnan jött).
|
| 71 |
+
# De ez elronthatja a flow-t, ha a Lingo Space-re akar navigálni.
|
| 72 |
+
return response
|
| 73 |
+
|
| 74 |
+
return router
|
src/wordgame/public/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Public app package – a WordGame (HF Space) app indul el ebben a módban.
|
| 2 |
+
|
| 3 |
+
A `humut-WordGame.hf.space` deployment csak a játékot, a bejelentkezést
|
| 4 |
+
és a publikus böngészhető oldalakat szolgálja ki (jatek, rangletra,
|
| 5 |
+
premium, login, register). Minden más (dashboard, szobák, deck, invite,
|
| 6 |
+
admin, paddle webhook) a private Lingo appban fut.
|
| 7 |
+
"""
|
src/wordgame/public/routes/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Public app route-jai."""
|
| 2 |
+
from . import game_routes, auth_routes
|
| 3 |
+
|
| 4 |
+
__all__ = ["game_routes", "auth_routes"]
|
src/wordgame/{api → public}/routes/auth_routes.py
RENAMED
|
@@ -1,37 +1,38 @@
|
|
| 1 |
-
"""Authentication routes - login, register, password reset.
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 4 |
from starlette.templating import Jinja2Templates
|
|
|
|
| 5 |
from ...core.database import supabase
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 9 |
-
"""Create authentication routes router.
|
| 10 |
-
|
| 11 |
-
Args:
|
| 12 |
-
templates: Jinja2 templates instance
|
| 13 |
-
|
| 14 |
-
Returns:
|
| 15 |
-
Configured APIRouter
|
| 16 |
-
"""
|
| 17 |
router = APIRouter()
|
| 18 |
-
|
| 19 |
@router.get("/login-page", response_class=HTMLResponse)
|
| 20 |
async def login_page(request: Request):
|
| 21 |
-
"""Display login form."""
|
| 22 |
return templates.TemplateResponse(request=request, name="login.html")
|
| 23 |
-
|
| 24 |
@router.get("/register-page", response_class=HTMLResponse)
|
| 25 |
async def register_page(request: Request):
|
| 26 |
-
"""Display registration form."""
|
| 27 |
return templates.TemplateResponse(request=request, name="register.html")
|
| 28 |
-
|
| 29 |
@router.post("/register", response_class=HTMLResponse)
|
| 30 |
-
async def auth_register(
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
try:
|
| 33 |
-
|
| 34 |
-
|
| 35 |
return HTMLResponse(content="""
|
| 36 |
<div class="p-4 bg-green-900/40 border border-green-500/30 rounded text-center text-green-400">
|
| 37 |
🎉 Regisztráció sikeres!
|
|
@@ -42,50 +43,43 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 42 |
return HTMLResponse(
|
| 43 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded'>{str(e)}</div>"
|
| 44 |
)
|
| 45 |
-
|
| 46 |
@router.post("/login", response_class=HTMLResponse)
|
| 47 |
-
async def auth_login(
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
try:
|
| 50 |
res = supabase.auth.sign_in_with_password({"email": email, "password": password})
|
| 51 |
token = res.session.access_token
|
| 52 |
-
|
| 53 |
response = HTMLResponse(content="<script>window.location.reload();</script>")
|
| 54 |
-
|
| 55 |
-
key="access_token",
|
| 56 |
-
value=token,
|
| 57 |
-
httponly=True,
|
| 58 |
-
max_age=3600,
|
| 59 |
-
expires=3600,
|
| 60 |
-
samesite="lax",
|
| 61 |
-
secure=False
|
| 62 |
-
)
|
| 63 |
return response
|
| 64 |
except Exception as e:
|
| 65 |
return HTMLResponse(
|
| 66 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded'>{str(e)}</div>"
|
| 67 |
)
|
| 68 |
-
|
| 69 |
@router.get("/logout")
|
| 70 |
-
async def auth_logout(
|
| 71 |
-
"""Handle user logout."""
|
| 72 |
try:
|
| 73 |
supabase.auth.sign_out()
|
| 74 |
except Exception:
|
| 75 |
pass
|
| 76 |
-
|
| 77 |
response = RedirectResponse(url="/", status_code=303)
|
| 78 |
-
|
| 79 |
return response
|
| 80 |
-
|
| 81 |
@router.get("/forgot-password", response_class=HTMLResponse)
|
| 82 |
async def forgot_password_page(request: Request):
|
| 83 |
-
"""Display forgot password form."""
|
| 84 |
return templates.TemplateResponse(request=request, name="forgot-password.html")
|
| 85 |
-
|
| 86 |
@router.post("/forgot-password", response_class=HTMLResponse)
|
| 87 |
-
async def auth_forgot_password(
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
try:
|
| 90 |
supabase.auth.reset_password_email(
|
| 91 |
email=email,
|
|
@@ -100,15 +94,17 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 100 |
return HTMLResponse(
|
| 101 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded text-sm'>{str(e)}</div>"
|
| 102 |
)
|
| 103 |
-
|
| 104 |
@router.get("/reset-password", response_class=HTMLResponse)
|
| 105 |
async def reset_password_page(request: Request):
|
| 106 |
-
"""Display reset password form."""
|
| 107 |
return templates.TemplateResponse(request=request, name="reset-password.html")
|
| 108 |
-
|
| 109 |
@router.post("/reset-password", response_class=HTMLResponse)
|
| 110 |
-
async def auth_reset_password(
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
try:
|
| 113 |
supabase.auth.update_user(
|
| 114 |
{"password": password},
|
|
@@ -126,5 +122,5 @@ def create_router(templates: Jinja2Templates) -> APIRouter:
|
|
| 126 |
return HTMLResponse(
|
| 127 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded text-sm'>{str(e)}</div>"
|
| 128 |
)
|
| 129 |
-
|
| 130 |
-
return router
|
|
|
|
| 1 |
+
"""Authentication routes - login, register, password reset (public/WordGame).
|
| 2 |
+
|
| 3 |
+
A public WordGame Space-en fut, de a session-t a Lingo Space is
|
| 4 |
+
felhasználja (cross-domain SSO). A cookie beállítás a `core.auth`
|
| 5 |
+
központi helper-ein keresztül történik, így a samesite/secure
|
| 6 |
+
beállítások konzisztensek mindkét appban.
|
| 7 |
+
"""
|
| 8 |
+
from fastapi import APIRouter, Request, Form
|
| 9 |
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 10 |
from starlette.templating import Jinja2Templates
|
| 11 |
+
|
| 12 |
from ...core.database import supabase
|
| 13 |
+
from ...core.auth import set_access_cookie, clear_access_cookie
|
| 14 |
|
| 15 |
|
| 16 |
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 17 |
+
"""Create authentication routes router."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
router = APIRouter()
|
| 19 |
+
|
| 20 |
@router.get("/login-page", response_class=HTMLResponse)
|
| 21 |
async def login_page(request: Request):
|
|
|
|
| 22 |
return templates.TemplateResponse(request=request, name="login.html")
|
| 23 |
+
|
| 24 |
@router.get("/register-page", response_class=HTMLResponse)
|
| 25 |
async def register_page(request: Request):
|
|
|
|
| 26 |
return templates.TemplateResponse(request=request, name="register.html")
|
| 27 |
+
|
| 28 |
@router.post("/register", response_class=HTMLResponse)
|
| 29 |
+
async def auth_register(
|
| 30 |
+
request: Request,
|
| 31 |
+
email: str = Form(...),
|
| 32 |
+
password: str = Form(...)
|
| 33 |
+
):
|
| 34 |
try:
|
| 35 |
+
supabase.auth.sign_up({"email": email, "password": password})
|
|
|
|
| 36 |
return HTMLResponse(content="""
|
| 37 |
<div class="p-4 bg-green-900/40 border border-green-500/30 rounded text-center text-green-400">
|
| 38 |
🎉 Regisztráció sikeres!
|
|
|
|
| 43 |
return HTMLResponse(
|
| 44 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded'>{str(e)}</div>"
|
| 45 |
)
|
| 46 |
+
|
| 47 |
@router.post("/login", response_class=HTMLResponse)
|
| 48 |
+
async def auth_login(
|
| 49 |
+
request: Request,
|
| 50 |
+
email: str = Form(...),
|
| 51 |
+
password: str = Form(...)
|
| 52 |
+
):
|
| 53 |
try:
|
| 54 |
res = supabase.auth.sign_in_with_password({"email": email, "password": password})
|
| 55 |
token = res.session.access_token
|
|
|
|
| 56 |
response = HTMLResponse(content="<script>window.location.reload();</script>")
|
| 57 |
+
set_access_cookie(response, token, max_age=3600)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return response
|
| 59 |
except Exception as e:
|
| 60 |
return HTMLResponse(
|
| 61 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded'>{str(e)}</div>"
|
| 62 |
)
|
| 63 |
+
|
| 64 |
@router.get("/logout")
|
| 65 |
+
async def auth_logout():
|
|
|
|
| 66 |
try:
|
| 67 |
supabase.auth.sign_out()
|
| 68 |
except Exception:
|
| 69 |
pass
|
|
|
|
| 70 |
response = RedirectResponse(url="/", status_code=303)
|
| 71 |
+
clear_access_cookie(response)
|
| 72 |
return response
|
| 73 |
+
|
| 74 |
@router.get("/forgot-password", response_class=HTMLResponse)
|
| 75 |
async def forgot_password_page(request: Request):
|
|
|
|
| 76 |
return templates.TemplateResponse(request=request, name="forgot-password.html")
|
| 77 |
+
|
| 78 |
@router.post("/forgot-password", response_class=HTMLResponse)
|
| 79 |
+
async def auth_forgot_password(
|
| 80 |
+
request: Request,
|
| 81 |
+
email: str = Form(...)
|
| 82 |
+
):
|
| 83 |
try:
|
| 84 |
supabase.auth.reset_password_email(
|
| 85 |
email=email,
|
|
|
|
| 94 |
return HTMLResponse(
|
| 95 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded text-sm'>{str(e)}</div>"
|
| 96 |
)
|
| 97 |
+
|
| 98 |
@router.get("/reset-password", response_class=HTMLResponse)
|
| 99 |
async def reset_password_page(request: Request):
|
|
|
|
| 100 |
return templates.TemplateResponse(request=request, name="reset-password.html")
|
| 101 |
+
|
| 102 |
@router.post("/reset-password", response_class=HTMLResponse)
|
| 103 |
+
async def auth_reset_password(
|
| 104 |
+
request: Request,
|
| 105 |
+
password: str = Form(...),
|
| 106 |
+
access_token: str = Form(...)
|
| 107 |
+
):
|
| 108 |
try:
|
| 109 |
supabase.auth.update_user(
|
| 110 |
{"password": password},
|
|
|
|
| 122 |
return HTMLResponse(
|
| 123 |
content=f"<div class='text-red-500 font-bold text-center p-2 bg-red-950/30 border border-red-500/30 rounded text-sm'>{str(e)}</div>"
|
| 124 |
)
|
| 125 |
+
|
| 126 |
+
return router
|
src/wordgame/public/routes/game_routes.py
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Public (WordGame) game routes - kompakt, önálló implementáció.
|
| 2 |
+
|
| 3 |
+
A korábbi 1308 soros `api/routes/game_routes.py` helyett egy
|
| 4 |
+
karbantarthatóbb, kompakt verzió. A játéklogika a `core.game_data`
|
| 5 |
+
modulból importálható, ha szét akarjuk választani.
|
| 6 |
+
|
| 7 |
+
Támogatott kategóriák: szleng, matek, gamer + 13 leggyakoribb nyelv.
|
| 8 |
+
A teljes ~90 nyelvet a `core/game_data.NYELV_BILLENTYUZET` tartalmazza
|
| 9 |
+
(itt a legszükségesebbeket tartjuk, hogy a fájl mérete kezelhető maradjon).
|
| 10 |
+
"""
|
| 11 |
+
import hashlib
|
| 12 |
+
import os
|
| 13 |
+
from datetime import date
|
| 14 |
+
from collections import Counter
|
| 15 |
+
from typing import Optional
|
| 16 |
+
|
| 17 |
+
from fastapi import APIRouter, Request, Cookie
|
| 18 |
+
from fastapi.responses import HTMLResponse
|
| 19 |
+
from starlette.templating import Jinja2Templates
|
| 20 |
+
|
| 21 |
+
from ...core.database import supabase
|
| 22 |
+
from ...core.config import settings
|
| 23 |
+
from ...core.auth import get_user_optional, ACCESS_TOKEN_COOKIE
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
KATEGORIA_NEVEK = {
|
| 27 |
+
"szleng": "🔥 MAI SZLENG",
|
| 28 |
+
"matek": "🔢 MATEK MOD",
|
| 29 |
+
"gamer": "🎮 GAMER SPEC",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
DEFAULT_KEYBOARD = [
|
| 33 |
+
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 34 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
|
| 35 |
+
["Z", "X", "C", "V", "B", "N", "M"],
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
NYELV_BILLENTYUZET = {
|
| 39 |
+
"en": DEFAULT_KEYBOARD,
|
| 40 |
+
"hu": [
|
| 41 |
+
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ő", "Ú"],
|
| 42 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "É", "Á", "Ó"],
|
| 43 |
+
["Y", "X", "C", "V", "B", "N", "M", "Ö", "Ü", "Ű", "Í"],
|
| 44 |
+
],
|
| 45 |
+
"de": [
|
| 46 |
+
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ü"],
|
| 47 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ö", "Ä"],
|
| 48 |
+
["Y", "X", "C", "V", "B", "N", "M", "ß"],
|
| 49 |
+
],
|
| 50 |
+
"fr": [
|
| 51 |
+
["A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 52 |
+
["Q", "S", "D", "F", "G", "H", "J", "K", "L", "M"],
|
| 53 |
+
["W", "X", "C", "V", "B", "N", "À", "Ç", "É", "È"],
|
| 54 |
+
],
|
| 55 |
+
"es": [
|
| 56 |
+
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 57 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ñ"],
|
| 58 |
+
["Z", "X", "C", "V", "B", "N", "M"],
|
| 59 |
+
],
|
| 60 |
+
"it": [
|
| 61 |
+
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "È", "É"],
|
| 62 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "À", "Ù"],
|
| 63 |
+
["Z", "X", "C", "V", "B", "N", "M"],
|
| 64 |
+
],
|
| 65 |
+
"pt": [
|
| 66 |
+
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 67 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ç", "Ã", "Õ"],
|
| 68 |
+
["Z", "X", "C", "V", "B", "N", "M"],
|
| 69 |
+
],
|
| 70 |
+
"pl": [
|
| 71 |
+
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
| 72 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ą", "Ó"],
|
| 73 |
+
["Z", "X", "C", "V", "B", "N", "M", "Ś", "Ż", "Ź", "Ć", "Ń", "Ł"],
|
| 74 |
+
],
|
| 75 |
+
"nl": DEFAULT_KEYBOARD,
|
| 76 |
+
"ru": [
|
| 77 |
+
["Й", "Ц", "У", "К", "Е", "Н", "Г", "Ш", "Щ", "З", "Х", "Ъ"],
|
| 78 |
+
["Ф", "Ы", "В", "А", "П", "Р", "О", "Л", "Д", "Ж", "Э"],
|
| 79 |
+
["Я", "Ч", "С", "М", "И", "Т", "Ь", "Б", "Ю", "Ё"],
|
| 80 |
+
],
|
| 81 |
+
"el": [
|
| 82 |
+
[";", "ς", "Ε", "Ρ", "Τ", "Υ", "Θ", "Ι", "Ο", "Π"],
|
| 83 |
+
["Α", "Σ", "Δ", "Φ", "Γ", "Η", "Ξ", "Κ", "Λ"],
|
| 84 |
+
["Ζ", "Χ", "Ψ", "Ω", "Β", "Ν", "Μ", "Ά", "Έ", "Ή", "Ί", "Ό", "Ύ", "Ώ"],
|
| 85 |
+
],
|
| 86 |
+
"tr": [
|
| 87 |
+
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Ğ", "Ü"],
|
| 88 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ş", "İ"],
|
| 89 |
+
["Z", "X", "C", "V", "B", "N", "M", "Ö", "Ç"],
|
| 90 |
+
],
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
NYELV_ORSZAG_TERKEP = {
|
| 94 |
+
"en": ["GB", "US", "IE", "AU", "NZ", "CA", "ZA", "NG", "KE", "IN", "PK", "BD"],
|
| 95 |
+
"hu": ["HU"],
|
| 96 |
+
"de": ["DE", "AT", "CH", "LI", "LU", "BE"],
|
| 97 |
+
"fr": ["FR", "BE", "CH", "LU", "MC", "CA"],
|
| 98 |
+
"es": ["ES", "MX", "AR", "CO", "PE", "VE", "CL"],
|
| 99 |
+
"it": ["IT", "CH", "SM", "VA"],
|
| 100 |
+
"pt": ["PT", "BR", "AO", "MZ"],
|
| 101 |
+
"pl": ["PL"],
|
| 102 |
+
"nl": ["NL", "BE", "SR"],
|
| 103 |
+
"ru": ["RU", "BY", "KZ"],
|
| 104 |
+
"el": ["GR", "CY"],
|
| 105 |
+
"tr": ["TR"],
|
| 106 |
+
"ja": ["JP"],
|
| 107 |
+
"zh": ["CN", "TW", "HK"],
|
| 108 |
+
"ko": ["KR"],
|
| 109 |
+
"ar": ["EG", "SA", "AE"],
|
| 110 |
+
"hi": ["IN"],
|
| 111 |
+
"he": ["IL"],
|
| 112 |
+
"th": ["TH"],
|
| 113 |
+
"vi": ["VN"],
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def get_billentyuzet(kategoria_tipus: str) -> list:
|
| 118 |
+
"""Get keyboard layout for a specific language/category."""
|
| 119 |
+
return NYELV_BILLENTYUZET.get(kategoria_tipus, DEFAULT_KEYBOARD)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def orszagkodbol_nyelv(orszagkod: str) -> str:
|
| 123 |
+
"""Get language code from country code."""
|
| 124 |
+
orszagkod_felso = orszagkod.upper()
|
| 125 |
+
for nyelv, orszagok in NYELV_ORSZAG_TERKEP.items():
|
| 126 |
+
if orszagkod_felso in orszagok:
|
| 127 |
+
return nyelv
|
| 128 |
+
return "en"
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def betoltesz_szavak_fajlbol(nyelv: str) -> list:
|
| 132 |
+
"""Load words from the 1000-most-common word file for a specific language."""
|
| 133 |
+
nyelv_fajl_terkep = {
|
| 134 |
+
"en": "1000-common-english-words.txt",
|
| 135 |
+
"hu": "1000-most-common-hungarian-words.txt",
|
| 136 |
+
"de": "1000-most-common-german-words.txt",
|
| 137 |
+
"fr": "1000-most-common-french-words.txt",
|
| 138 |
+
"es": "1000-most-common-spanish-words.txt",
|
| 139 |
+
"it": "1000-most-common-italian-words.txt",
|
| 140 |
+
"pt": "1000-most-common-portuguese-words.txt",
|
| 141 |
+
"pl": "1000-most-common-polish-words.txt",
|
| 142 |
+
"nl": "1000-most-common-dutch-words.txt",
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
fajlnev = nyelv_fajl_terkep.get(nyelv)
|
| 146 |
+
if not fajlnev:
|
| 147 |
+
return []
|
| 148 |
+
|
| 149 |
+
possible_paths = [
|
| 150 |
+
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "static", "1000-most-common", fajlnev),
|
| 151 |
+
os.path.join("static", "1000-most-common", fajlnev),
|
| 152 |
+
]
|
| 153 |
+
for path in possible_paths:
|
| 154 |
+
if os.path.exists(path):
|
| 155 |
+
try:
|
| 156 |
+
with open(path, "r", encoding="utf-8") as f:
|
| 157 |
+
words = []
|
| 158 |
+
for line in f.readlines():
|
| 159 |
+
line = line.strip()
|
| 160 |
+
if not line:
|
| 161 |
+
continue
|
| 162 |
+
if "|" in line:
|
| 163 |
+
parts = line.split("|", 1)
|
| 164 |
+
word = parts[1].strip() if len(parts) > 1 else parts[0].strip()
|
| 165 |
+
else:
|
| 166 |
+
word = line
|
| 167 |
+
word = "".join(c for c in word if c.isalpha()).upper()
|
| 168 |
+
if word and len(word) >= 3:
|
| 169 |
+
words.append(word)
|
| 170 |
+
return words
|
| 171 |
+
except Exception as e:
|
| 172 |
+
print(f"Error loading word file {path}: {e}")
|
| 173 |
+
return []
|
| 174 |
+
return []
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def get_daily_word(kategoria: str = "szleng") -> str:
|
| 178 |
+
"""Get daily word based on date - deterministic selection from word list."""
|
| 179 |
+
today = date.today()
|
| 180 |
+
day_seed = f"{today.isoformat()}-{kategoria}"
|
| 181 |
+
day_hash = int(hashlib.md5(day_seed.encode()).hexdigest(), 16)
|
| 182 |
+
|
| 183 |
+
if kategoria in NYELV_BILLENTYUZET:
|
| 184 |
+
words = betoltesz_szavak_fajlbol(kategoria)
|
| 185 |
+
if words:
|
| 186 |
+
ot_betus_szavak = [w for w in words if len(w) == 5]
|
| 187 |
+
if ot_betus_szavak:
|
| 188 |
+
return ot_betus_szavak[day_hash % len(ot_betus_szavak)]
|
| 189 |
+
if words:
|
| 190 |
+
return words[day_hash % len(words)][:5].upper()
|
| 191 |
+
|
| 192 |
+
try:
|
| 193 |
+
response = supabase.table(settings.TABLE_WORDS)\
|
| 194 |
+
.select("szo, kategoriak(nev)")\
|
| 195 |
+
.eq("kategoriak.nev", kategoria)\
|
| 196 |
+
.execute()
|
| 197 |
+
if response.data:
|
| 198 |
+
words = [w["szo"].upper() for w in response.data]
|
| 199 |
+
return words[day_hash % len(words)]
|
| 200 |
+
except Exception:
|
| 201 |
+
pass
|
| 202 |
+
return "CRING"
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def generate_share_text(kategoria: str, probalkozasok: int, kategoria_nev: str) -> str:
|
| 206 |
+
today = date.today().strftime("%Y.%m.%d.")
|
| 207 |
+
emojis = "🟩" * probalkozasok + "⬛" * (6 - probalkozasok)
|
| 208 |
+
return f"Szó-Kavalkád {today}\n{kategoria_nev}\n{probalkozasok}/6\n\n{emojis}"
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def create_router(templates: Jinja2Templates) -> APIRouter:
|
| 212 |
+
"""Create the public game router."""
|
| 213 |
+
router = APIRouter()
|
| 214 |
+
|
| 215 |
+
@router.get("/", response_class=HTMLResponse)
|
| 216 |
+
async def index(
|
| 217 |
+
request: Request,
|
| 218 |
+
access_token: Optional[str] = Cookie(default=None, alias=ACCESS_TOKEN_COOKIE)
|
| 219 |
+
):
|
| 220 |
+
"""Home page - loads default daily game."""
|
| 221 |
+
user = await get_user_optional(access_token)
|
| 222 |
+
return templates.TemplateResponse(
|
| 223 |
+
request=request,
|
| 224 |
+
name="base.html",
|
| 225 |
+
context={"user": user, "default_kategoria": "szleng"}
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
@router.get("/jatek-valaszto", response_class=HTMLResponse)
|
| 229 |
+
async def jatek_valaszto_page(
|
| 230 |
+
request: Request,
|
| 231 |
+
access_token: Optional[str] = Cookie(default=None, alias=ACCESS_TOKEN_COOKIE)
|
| 232 |
+
):
|
| 233 |
+
"""Game selector page."""
|
| 234 |
+
user = await get_user_optional(access_token)
|
| 235 |
+
return templates.TemplateResponse(
|
| 236 |
+
request=request,
|
| 237 |
+
name="jatek-valaszto.html",
|
| 238 |
+
context={"request": request, "user": user}
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
@router.get("/jatek/{kategoria}", response_class=HTMLResponse)
|
| 242 |
+
async def jatek_betoltes(request: Request, kategoria: str, orszag: str = None):
|
| 243 |
+
"""Load game for specific category with optional country-based language."""
|
| 244 |
+
if kategoria == "nyelv" and orszag:
|
| 245 |
+
nyelv = orszagkodbol_nyelv(orszag)
|
| 246 |
+
kategoria_nev = f"🌍 {nyelv.upper()} - NAPI SZÓ"
|
| 247 |
+
kategoria_tipus = nyelv
|
| 248 |
+
else:
|
| 249 |
+
kategoria_nev = KATEGORIA_NEVEK.get(kategoria, kategoria)
|
| 250 |
+
kategoria_tipus = kategoria
|
| 251 |
+
|
| 252 |
+
billentyuzet = get_billentyuzet(kategoria_tipus)
|
| 253 |
+
return templates.TemplateResponse(
|
| 254 |
+
request=request,
|
| 255 |
+
name="jatek.html",
|
| 256 |
+
context={
|
| 257 |
+
"kategoria_tipus": kategoria_tipus,
|
| 258 |
+
"kategoria_nev": kategoria_nev,
|
| 259 |
+
"billentyuzet": billentyuzet
|
| 260 |
+
}
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
@router.post("/ellenorzes", response_class=HTMLResponse)
|
| 264 |
+
async def ellenoriz_tipp(request: Request):
|
| 265 |
+
"""Check guess against answer word."""
|
| 266 |
+
try:
|
| 267 |
+
body = await request.form()
|
| 268 |
+
tipp = body.get("tipp", "")
|
| 269 |
+
sor = int(body.get("sor", 0))
|
| 270 |
+
kategoria = body.get("kategoria", "szleng")
|
| 271 |
+
except Exception:
|
| 272 |
+
return HTMLResponse(
|
| 273 |
+
content="<div class='text-red-500 font-bold'>HIBA: Nem sikerült feldolgozni!</div>"
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
tipp = tipp.upper()
|
| 277 |
+
megfejtes = get_daily_word(kategoria)
|
| 278 |
+
|
| 279 |
+
n = len(megfejtes)
|
| 280 |
+
if len(tipp) != n:
|
| 281 |
+
return HTMLResponse(
|
| 282 |
+
content="<div class='text-red-500 font-bold'>HIBA: Hibás karakterhossz!</div>"
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
statuszok = ["szurke"] * n
|
| 286 |
+
megfejtes_szamlalo = Counter(megfejtes)
|
| 287 |
+
for i in range(n):
|
| 288 |
+
if tipp[i] == megfejtes[i]:
|
| 289 |
+
statuszok[i] = "zold"
|
| 290 |
+
megfejtes_szamlalo[tipp[i]] -= 1
|
| 291 |
+
for i in range(n):
|
| 292 |
+
if statuszok[i] != "zold":
|
| 293 |
+
if megfejtes_szamlalo.get(tipp[i], 0) > 0:
|
| 294 |
+
statuszok[i] = "sarga"
|
| 295 |
+
megfejtes_szamlalo[tipp[i]] -= 1
|
| 296 |
+
|
| 297 |
+
grid_style = f'style="grid-template-columns: repeat({n}, minmax(0, 1fr));"'
|
| 298 |
+
html_valasz = f'<div class="wordle-sor grid gap-2 w-full animate-bounce" {grid_style}>'
|
| 299 |
+
for i in range(n):
|
| 300 |
+
szin_class = "bg-gray-800 border-gray-900 text-gray-400"
|
| 301 |
+
if statuszok[i] == "zold":
|
| 302 |
+
szin_class = "bg-green-600 border-green-700 text-white scale-105"
|
| 303 |
+
elif statuszok[i] == "sarga":
|
| 304 |
+
szin_class = "bg-yellow-500 border-yellow-600 text-white"
|
| 305 |
+
html_valasz += (
|
| 306 |
+
f'<div class="wordle-cella flex items-center justify-center '
|
| 307 |
+
f'text-2xl font-bold uppercase border-2 rounded select-none '
|
| 308 |
+
f'aspect-square {szin_class}">{tipp[i]}</div>'
|
| 309 |
+
)
|
| 310 |
+
html_valasz += '</div>'
|
| 311 |
+
|
| 312 |
+
if tipp == megfejtes:
|
| 313 |
+
probalkozasok_szama = sor + 1
|
| 314 |
+
share_text = generate_share_text(
|
| 315 |
+
kategoria, probalkozasok_szama,
|
| 316 |
+
KATEGORIA_NEVEK.get(kategoria, kategoria)
|
| 317 |
+
)
|
| 318 |
+
share_text_attr = share_text.replace('"', '"')
|
| 319 |
+
html_valasz += f"""
|
| 320 |
+
<div hx-swap-oob="beforeend:#jatek-terulet">
|
| 321 |
+
<div class="mt-4 p-4 bg-green-900/40 border border-green-500/30 rounded text-center w-full max-w-md">
|
| 322 |
+
<p class="font-bold text-green-400 text-lg">🎉 GRATULÁLUNK! Sikerült!</p>
|
| 323 |
+
<p class="text-sm text-gray-300 mt-2">{probalkozasok_szama}/6 próbálkozásból</p>
|
| 324 |
+
<div class="mt-3 flex gap-2 justify-center">
|
| 325 |
+
<button data-share-text="{share_text_attr}"
|
| 326 |
+
class="share-gomb px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white font-bold rounded text-sm cursor-pointer border-0 transition">
|
| 327 |
+
📋 Megosztás
|
| 328 |
+
</button>
|
| 329 |
+
</div>
|
| 330 |
+
</div>
|
| 331 |
+
</div>
|
| 332 |
+
"""
|
| 333 |
+
return HTMLResponse(content=html_valasz)
|
| 334 |
+
|
| 335 |
+
@router.get("/rangletra", response_class=HTMLResponse)
|
| 336 |
+
async def rangletra(request: Request, kat: str = "szleng"):
|
| 337 |
+
"""Display leaderboard."""
|
| 338 |
+
try:
|
| 339 |
+
response = (
|
| 340 |
+
supabase.table(settings.TABLE_LEADERBOARD)
|
| 341 |
+
.select("username, pontszam, ido_masodperc, is_premium")
|
| 342 |
+
.eq("kategoria", kat)
|
| 343 |
+
.order("pontszam.desc(),ido_masodperc.asc()")
|
| 344 |
+
.execute()
|
| 345 |
+
)
|
| 346 |
+
lista = [
|
| 347 |
+
{
|
| 348 |
+
"nev": item.get("username"),
|
| 349 |
+
"ido": item.get("ido_masodperc"),
|
| 350 |
+
"pont": item.get("pontszam"),
|
| 351 |
+
"is_premium": item.get("is_premium", False),
|
| 352 |
+
}
|
| 353 |
+
for item in (response.data or [])
|
| 354 |
+
]
|
| 355 |
+
except Exception:
|
| 356 |
+
lista = []
|
| 357 |
+
return templates.TemplateResponse(
|
| 358 |
+
request=request,
|
| 359 |
+
name="rangletra.html",
|
| 360 |
+
context={"toplista": list(enumerate(lista, start=1))}
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
@router.get("/premium", response_class=HTMLResponse)
|
| 364 |
+
async def premium_oldal(request: Request):
|
| 365 |
+
"""Premium membership page."""
|
| 366 |
+
return HTMLResponse(content="""
|
| 367 |
+
<div class="w-full max-w-md bg-gray-950 border border-amber-500/30 rounded-xl p-6 text-center shadow-2xl animate-fade-in mx-auto">
|
| 368 |
+
<h2 class="text-3xl font-black text-amber-400 mb-2">👑 Csatlakozz a Prémiumhoz</h2>
|
| 369 |
+
<p class="text-gray-400 text-sm mb-6">Tüntesd el a hirdetéseket, kapj egy egyedi ikont a ranglétrán és nyiss ki +5 titkos kategóriát!</p>
|
| 370 |
+
<div class="bg-gray-900 p-4 rounded-lg mb-6 border border-gray-800">
|
| 371 |
+
<span class="text-xs uppercase font-bold tracking-wider text-amber-500">Egyszeri díj (Örök tagság)</span>
|
| 372 |
+
<div class="text-3xl font-black text-white mt-1">1.490 Ft</div>
|
| 373 |
+
</div>
|
| 374 |
+
<button onclick="alert('Itt nyílna meg a Paddle fizetési kapu!')" class="w-full py-4 bg-gradient-to-r from-amber-500 via-yellow-500-to-amber-600 text-gray-950 font-black rounded-lg shadow-lg hover:brightness-110 active:scale-98 transition cursor-pointer uppercase tracking-wider text-sm">Vásárlás most</button>
|
| 375 |
+
</div>
|
| 376 |
+
""")
|
| 377 |
+
|
| 378 |
+
return router
|
src/wordgame/shared/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared app package – közös route-ok (mindkét app regisztrálja).
|
| 2 |
+
|
| 3 |
+
A healthcheck és egyéb, mindkét deployment-en elérhető utility
|
| 4 |
+
route-ok tartoznak ide (pl. /health, /ready a HF Space healthcheck-hez).
|
| 5 |
+
"""
|
src/wordgame/shared/routes/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared route-ok."""
|
| 2 |
+
from . import health_routes
|
| 3 |
+
|
| 4 |
+
__all__ = ["health_routes"]
|
src/wordgame/shared/routes/health_routes.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Health és readiness check route-ok – mindkét app regisztrálja.
|
| 2 |
+
|
| 3 |
+
A HF Space-ek healthcheck endpoint-ot várnak el a deploy-ok
|
| 4 |
+
állapotának monitorozásához.
|
| 5 |
+
"""
|
| 6 |
+
from fastapi import APIRouter
|
| 7 |
+
from datetime import datetime, timezone
|
| 8 |
+
from ...core.config import settings
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def create_router() -> APIRouter:
|
| 12 |
+
"""Create health/readiness routes router."""
|
| 13 |
+
router = APIRouter()
|
| 14 |
+
|
| 15 |
+
@router.get("/health", tags=["health"])
|
| 16 |
+
async def health():
|
| 17 |
+
"""Egyszerű liveness check – mindig 200, ha az app fut."""
|
| 18 |
+
return {
|
| 19 |
+
"status": "ok",
|
| 20 |
+
"service": settings.APP_NAME,
|
| 21 |
+
"mode": settings.APP_MODE,
|
| 22 |
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
@router.get("/ready", tags=["health"])
|
| 26 |
+
async def ready():
|
| 27 |
+
"""Readiness check – a Supabase kliens sikeresen inicializálódott-e."""
|
| 28 |
+
# Import itt, hogy a health check ne függjön a DB-től indításkor
|
| 29 |
+
from ...core.database import supabase
|
| 30 |
+
try:
|
| 31 |
+
# Egy olcsó ping – ha a kliens él, a settings elérhető
|
| 32 |
+
_ = supabase
|
| 33 |
+
return {"status": "ready", "mode": settings.APP_MODE}
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return {"status": "degraded", "error": str(e)}
|
| 36 |
+
|
| 37 |
+
return router
|
src/wordgame/templates/dashboard.html
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="hu" class="h-full">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Dashboard | Szó-Kavalkád</title>
|
| 7 |
+
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<link rel="stylesheet" href="/static/css/theme.css">
|
| 10 |
+
<style>
|
| 11 |
+
.animate-fade-in { animation: fadeIn 0.3s ease-out forwards; }
|
| 12 |
+
@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
|
| 13 |
+
</style>
|
| 14 |
+
</head>
|
| 15 |
+
<body class="flex flex-col min-h-screen font-sans antialiased" style="background-color: var(--bg-primary); color: var(--text-primary);">
|
| 16 |
+
|
| 17 |
+
<header class="border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-950 px-4 py-3 flex justify-between items-center">
|
| 18 |
+
<h1 class="text-xl font-black text-green-600 dark:text-green-500">SZÓ-KAVALKÁD DASHBOARD</h1>
|
| 19 |
+
<nav class="flex gap-4 text-sm font-medium items-center">
|
| 20 |
+
<a href="/{{ jatek_valaszto_url | default('/jatek-valaszto') }}" class="hover:text-green-600 dark:hover:text-green-400">Játék</a>
|
| 21 |
+
<a href="/auth/logout" class="text-red-500 hover:text-red-600 font-semibold text-xs uppercase">Kijelentkezés</a>
|
| 22 |
+
</nav>
|
| 23 |
+
</header>
|
| 24 |
+
|
| 25 |
+
<main class="flex-1 max-w-5xl mx-auto p-6 w-full">
|
| 26 |
+
<!-- User info -->
|
| 27 |
+
<div class="mb-6 p-4 bg-gray-100 dark:bg-gray-900 rounded-lg flex justify-between items-center">
|
| 28 |
+
<div>
|
| 29 |
+
<p class="text-sm text-gray-600 dark:text-gray-400">Bejelentkezve mint:</p>
|
| 30 |
+
<p class="font-mono text-sm">{{ user_email }}</p>
|
| 31 |
+
</div>
|
| 32 |
+
<div id="subscription-status" hx-get="/dashboard/subscription" hx-trigger="load" hx-swap="innerHTML">
|
| 33 |
+
<span class="text-gray-500">Betöltés...</span>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<!-- Deckek szekció -->
|
| 38 |
+
<section class="mb-8">
|
| 39 |
+
<div class="flex justify-between items-center mb-4">
|
| 40 |
+
<h2 class="text-2xl font-bold">📚 Paklik (Deck-ek)</h2>
|
| 41 |
+
<button hx-get="/dashboard/deck" hx-trigger="click once" class="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded text-sm font-bold">
|
| 42 |
+
Paklik frissítése
|
| 43 |
+
</button>
|
| 44 |
+
</div>
|
| 45 |
+
<div id="decks-list" hx-get="/dashboard/deck" hx-trigger="load" hx-swap="innerHTML" class="text-gray-500">
|
| 46 |
+
Betöltés...
|
| 47 |
+
</div>
|
| 48 |
+
</section>
|
| 49 |
+
|
| 50 |
+
<!-- Invite szekció -->
|
| 51 |
+
<section class="mb-8">
|
| 52 |
+
<h2 class="text-2xl font-bold mb-4">🔗 Meghívók</h2>
|
| 53 |
+
<div id="invites-list" hx-get="/dashboard/invite" hx-trigger="load" hx-swap="innerHTML" class="text-gray-500">
|
| 54 |
+
Betöltés...
|
| 55 |
+
</div>
|
| 56 |
+
</section>
|
| 57 |
+
|
| 58 |
+
<!-- Rejtett admin link (csak admin email-ű usereknek) -->
|
| 59 |
+
<footer class="mt-12 pt-6 border-t border-gray-200 dark:border-gray-800 text-center text-xs text-gray-400">
|
| 60 |
+
<p>user_id: <span class="font-mono">{{ user_id }}</span></p>
|
| 61 |
+
</footer>
|
| 62 |
+
</main>
|
| 63 |
+
|
| 64 |
+
<script src="/static/js/theme.js"></script>
|
| 65 |
+
</body>
|
| 66 |
+
</html>
|