oriqqqqqqat
commited on
Commit
·
06e9b23
1
Parent(s):
5a6d9e4
addcapcha
Browse files- main.py +36 -0
- templates/detect.html +5 -0
main.py
CHANGED
|
@@ -299,6 +299,42 @@ async def show_results(request: Request, result_id: str):
|
|
| 299 |
context = {"request": request, **cached_item["data"]}
|
| 300 |
return templates.TemplateResponse("detect.html", context)
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
# =============== รองรับ Render / Railway / VPS ================
|
| 304 |
if __name__ == "__main__":
|
|
|
|
| 299 |
context = {"request": request, **cached_item["data"]}
|
| 300 |
return templates.TemplateResponse("detect.html", context)
|
| 301 |
|
| 302 |
+
@app.post("/uploaded")
|
| 303 |
+
async def handle_upload(
|
| 304 |
+
request: Request,
|
| 305 |
+
file: UploadFile = File(...),
|
| 306 |
+
checkboxes: List[str] = Form([]),
|
| 307 |
+
symptom_text: str = Form(""),
|
| 308 |
+
cf_token: str = Form(alias="cf-turnstile-response")
|
| 309 |
+
):
|
| 310 |
+
|
| 311 |
+
# ===== CAPTCHA CHECK =====
|
| 312 |
+
TURNSTILE_SECRET = os.getenv("TURNSTILE_SECRET")
|
| 313 |
+
|
| 314 |
+
if not cf_token:
|
| 315 |
+
return templates.TemplateResponse(
|
| 316 |
+
"detect.html",
|
| 317 |
+
{"request": request, "error": "กรุณายืนยัน CAPTCHA ก่อนส่งข้อมูล"},
|
| 318 |
+
status_code=400
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
verify_response = requests.post(
|
| 322 |
+
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
| 323 |
+
data={
|
| 324 |
+
"secret": TURNSTILE_SECRET,
|
| 325 |
+
"response": cf_token,
|
| 326 |
+
"remoteip": request.client.host
|
| 327 |
+
}
|
| 328 |
+
).json()
|
| 329 |
+
|
| 330 |
+
if not verify_response.get("success", False):
|
| 331 |
+
return templates.TemplateResponse(
|
| 332 |
+
"detect.html",
|
| 333 |
+
{"request": request, "error": "CAPTCHA ไม่ผ่านการตรวจสอบ กรุณาลองใหม่"},
|
| 334 |
+
status_code=400
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
|
| 338 |
|
| 339 |
# =============== รองรับ Render / Railway / VPS ================
|
| 340 |
if __name__ == "__main__":
|
templates/detect.html
CHANGED
|
@@ -103,6 +103,11 @@
|
|
| 103 |
<label for="symptomTextArea" class="form-label">รายละเอียดอาการเพิ่มเติม:</label>
|
| 104 |
<textarea class="form-control" id="symptomTextArea" name="symptom_text" rows="4" placeholder="เช่น มีอาการปวดเป็นบางครั้ง, เป็นมานาน 2 สัปดาห์ ..."></textarea>
|
| 105 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
<div class="mt-4 d-flex justify-content-center">
|
| 108 |
<button class="button" type="submit">Submit</button>
|
|
|
|
| 103 |
<label for="symptomTextArea" class="form-label">รายละเอียดอาการเพิ่มเติม:</label>
|
| 104 |
<textarea class="form-control" id="symptomTextArea" name="symptom_text" rows="4" placeholder="เช่น มีอาการปวดเป็นบางครั้ง, เป็นมานาน 2 สัปดาห์ ..."></textarea>
|
| 105 |
</div>
|
| 106 |
+
<div class="cf-turnstile mt-4 mb-3"
|
| 107 |
+
data-sitekey="0x4AAAAAACEfyPjr3pfV21Mm">
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
| 111 |
|
| 112 |
<div class="mt-4 d-flex justify-content-center">
|
| 113 |
<button class="button" type="submit">Submit</button>
|