- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
Latest commit
39 lines (31 loc) · 1.08 KB
/
Copy pathserver.py
File metadata and controls
39 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fromflaskimportFlask, request, jsonify
fromdotenvimportload_dotenv
importos, requests
fromflask_corsimportCORS
app=Flask(__name__)
CORS(app)
load_dotenv()
SECRET=os.getenv("RECAPTCHA_SECRET")
@app.post("/verify-recaptcha")
defverify_recaptcha():
data=request.get_json(silent=True)
token=data.get("token") ifdataelseNone
ifnottoken:
returnjsonify({"success": False, "error": "no-token"}), 400
ifnotSECRET:
returnjsonify({"success": False, "error": "not-configured"}), 500
# Verify with Google
try:
resp=requests.post(
"https://www.google.com/recaptcha/api/siteverify",
data={"secret": SECRET, "response": token},
timeout=5
).json()
exceptrequests.RequestException:
returnjsonify({"success": False, "error": "verify-unavailable"}), 502
ifresp.get("success"):
returnjsonify({"success": True})
else:
returnjsonify({"success": False, "error": resp.get("error-codes")}), 403
if__name__=="__main__":
app.run(host="0.0.0.0", port=3000)