diff options
| author | altaf-creator <dev@altafcreator.com> | 2026-05-01 12:27:42 +0800 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2026-05-01 12:27:42 +0800 |
| commit | cdfdd3a2d6bdd2ac37e2bd237b6e760864e41db1 (patch) | |
| tree | 5d692d9c28b01b4d508f94edd7a3b5e21cdee453 | |
| parent | db1c6676a13798ee57dbac429a1d5045b60356fb (diff) | |
new backend + turnstile
| -rw-r--r-- | backend/main.py | 48 | ||||
| -rw-r--r-- | www/index.html | 8 | ||||
| -rw-r--r-- | www/projects/index.html | 9 | ||||
| -rw-r--r-- | www/scripts/captcha.js | 17 | ||||
| -rw-r--r-- | www/style.css | 6 |
5 files changed, 86 insertions, 2 deletions
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 @@ <link rel="me" href="https://mastodon.gamedev.place/@altaf"> <title>This is altaf-creator</title> <link rel="stylesheet" href="/packages/fontawesome-free-6.5.2-web/css/all.css"> + <link rel="preconnect" href="https://challenges.cloudflare.com" /> + <!-- Cloudflare Turnstile --> + <script + src="https://challenges.cloudflare.com/turnstile/v0/api.js" + async + defer + ></script> </head> <body onload="index();"> @@ -148,6 +155,7 @@ <li><a class="link" href="https://git.altafcreator.com/"><i class="fa-brands fa-git-alt"></i> altaf-git<span class="desktop">: source code repositories for all my projects</span></a></li> </ul> <h1>Contact Me!</h1> + <div class="cf-turnstile" data-sitekey="0x4AAAAAAC1yqhk5tXbXfvXw" data-callback="onTurnstileSuccess"></div> <ul> <li>For <b>business<span class="desktop"> inquiries</span></b>: <a href="mailto:@.com" class="link"><i class="fa-solid fa-envelope"></i> hidden for now, too many spam</a></li> <li>For <span class="desktop">contacting me </span><b>personal<span class="desktop">ly</span></b>: <a href="mailto:@.com" class="link"><i class="fa-solid fa-envelope"></i> hidden for now, too many spam</a></li> diff --git a/www/projects/index.html b/www/projects/index.html index cd4c311..3b975a5 100644 --- a/www/projects/index.html +++ b/www/projects/index.html @@ -40,8 +40,13 @@ <div class="center-grid">
<div class="div-sizing" style="max-width: none;">
<div class="flex-container flex-container-column">
- <span class="heading">Projects</span>
- <a class="button center" href="//git.altafcreator.com" style="margin-left: auto; margin-right: auto;"><i class="fa-brands fa-git-alt"></i> Source Code to My Projects</a>
+ <p>
+ <span class="heading" style="display: inline;">Projects</span>
+ <br class="mobile">
+ <a class="link item-end" href="https://git.altafcreator.com">
+ <i class="fa-brands fa-git-alt"></i> Source Code for My Projects ↗
+ </a>
+ </p>
<div class="flex-container flex" id="top-project-highlight">
<div class="flex full-img-card highlight-card top-gallery-card"
style="background-image: url(/assets/images/game-hero/simplicity_screenshot.png); ">
diff --git a/www/scripts/captcha.js b/www/scripts/captcha.js new file mode 100644 index 0000000..2a58534 --- /dev/null +++ b/www/scripts/captcha.js @@ -0,0 +1,17 @@ +async function onTurnstileSuccess(token) { + const response = await fetch("https://backend.altafcreator.com", { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({"token": token}), + }); + + const result = await response.json(); + + if (result.status) { + alert(result); + } else { + alert("fail"); + } +} diff --git a/www/style.css b/www/style.css index 26378de..55cc0b8 100644 --- a/www/style.css +++ b/www/style.css @@ -378,6 +378,7 @@ li { color: black;
background-color: transparent;
z-index: 9999;
+ height: fit-content;
}
.link:hover {
@@ -466,6 +467,10 @@ li { place-self: center;
}
+.item-end {
+ place-self: end;
+}
+
.full-img-card {
background-color: var(--accent);
margin: 5px;
@@ -517,6 +522,7 @@ li { gap: 8px;
flex-direction: column;
margin-right: 8px;
+ pointer-events: none;
}
.full-img-card.highlight-card:hover {
|
