From cdfdd3a2d6bdd2ac37e2bd237b6e760864e41db1 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Fri, 1 May 2026 12:27:42 +0800 Subject: new backend + turnstile --- backend/main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ www/index.html | 8 ++++++++ www/projects/index.html | 9 +++++++-- www/scripts/captcha.js | 17 +++++++++++++++++ www/style.css | 6 ++++++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 backend/main.py create mode 100644 www/scripts/captcha.js diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..97481b6 --- /dev/null +++ b/backend/main.py @@ -0,0 +1,48 @@ +import fastapi +import requests +from dotenv import load_dotenv +from os import getenv + +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") + + +@app.post("/email") +def email(token): + if validate_turnstile(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 diff --git a/www/index.html b/www/index.html index 1e79d20..7a9c263 100644 --- a/www/index.html +++ b/www/index.html @@ -11,6 +11,13 @@ This is altaf-creator + + + @@ -148,6 +155,7 @@
  • altaf-git: source code repositories for all my projects
  • Contact Me!

    +