diff options
Diffstat (limited to 'backend/main.py')
| -rw-r--r-- | backend/main.py | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/backend/main.py b/backend/main.py deleted file mode 100644 index bf7f661..0000000 --- a/backend/main.py +++ /dev/null @@ -1,67 +0,0 @@ -import fastapi -from fastapi.middleware.cors import CORSMiddleware -import requests -from dotenv import load_dotenv -from os import getenv -from pydantic import BaseModel - -print("Hello, world!") -load_dotenv() - -app = fastapi.FastAPI(title="altafcreator.com", decscription="altafcreator.com API", version="1.0") -TURNSTILE_SECRET = getenv("CLOUDFLARE_TURNSTILE_SECRET").encode("utf-8") - -origins = [ - "http://localhost", - "https://altafcreator.com", - "https://backend.altafcreator.com" -] -app.add_middleware( - CORSMiddleware, - allow_origins=origins, - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) - - -class TurnstileTokenData(BaseModel): - token: str - - -@app.post("/email") -def email(data: TurnstileTokenData): - if validate_turnstile(data.token): - return { - "status": True, - "message": "here's my email", - "business": "business@altafcreator.com", - "personal": "altaf@altafcreator.com", - } - else: - return { - "status": False, - "message": "Turnstile verification invalid", - } - - -# https://developers.cloudflare.com/turnstile/get-started/server-side-validation/, modified -# returns response if success, returns None if unsuccessful. -def validate_turnstile(token, remoteip=None) -> tuple: - url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify' - - data = { - 'secret': TURNSTILE_SECRET, - 'response': token - } - - if remoteip: - data['remoteip'] = remoteip - - try: - response = requests.post(url, data=data, timeout=10) - response.raise_for_status() - return response.json() - except requests.RequestException as e: - print(f"Turnstile validation error: {e}") - return None |
