diff --git a/routes/dashboard.py b/routes/dashboard.py index 8dc39f51..3fb1f70c 100644 --- a/routes/dashboard.py +++ b/routes/dashboard.py @@ -1,4 +1,6 @@ from helpers import ( + abort, + message, flash, url_for, request, @@ -7,9 +9,15 @@ message, redirect, Blueprint, + RECAPTCHA, + requestsPost, DB_POSTS_ROOT, - DB_COMMENTS_ROOT, render_template, + DB_COMMENTS_ROOT, + RECAPTCHA_SITE_KEY, + RECAPTCHA_VERIFY_URL, + RECAPTCHA_SECRET_KEY, + RECAPTCHA_POST_DELETE, ) from delete import deletePost @@ -24,17 +32,35 @@ def dashboard(userName): case True: match request.method == "POST": case True: - match "postDeleteButton" in request.form: + match RECAPTCHA and RECAPTCHA_POST_DELETE: case True: + secretResponse = request.form[ + "g-recaptcha-response" + ] + verifyResponse = requestsPost( + url=f"{RECAPTCHA_VERIFY_URL}?secret={RECAPTCHA_SECRET_KEY}&response={secretResponse}" + ).json() + match verifyResponse[ + "success" + ] == True or verifyResponse[ + "score" + ] > 0.5: + case True: + message("2",f"POST DELETE RECAPTCHA | VERIFICATION: {verifyResponse["success"]} | VERIFICATION SCORE: {verifyResponse["score"]}") + deletePost(request.form["postID"]) + case False: + message("1",f"POST DELETE RECAPTCHA | VERIFICATION: {verifyResponse["success"]} | VERIFICATION SCORE: {verifyResponse["score"]}") + abort(401) + case False: deletePost(request.form["postID"]) - return ( - redirect( - url_for( - "dashboard.dashboard", userName=userName - ) - ), - 301, + return ( + redirect( + url_for( + "dashboard.dashboard", userName=userName, ) + ), + 301, + ) connection = sqlite3.connect(DB_POSTS_ROOT) cursor = connection.cursor() cursor.execute( @@ -64,7 +90,7 @@ def dashboard(userName): posts=posts, comments=comments, showPosts=showPosts, - showComments=showComments, + showComments=showComments, siteKey=RECAPTCHA_SITE_KEY, recaptcha=RECAPTCHA, ) case False: message( diff --git a/templates/standardUI/dashboard.html b/templates/standardUI/dashboard.html index 6a85f630..b0e316ed 100644 --- a/templates/standardUI/dashboard.html +++ b/templates/standardUI/dashboard.html @@ -20,6 +20,24 @@

Posts

{{post[3]|safe}}
edit + {% if recaptcha %} + + +
+ + + +
+ {% else %}
@@ -31,6 +49,7 @@

Posts

delete
+ {% endif %}

Tags: {{post[2]}}

diff --git a/templates/tailwindUI/dashboard.html b/templates/tailwindUI/dashboard.html index b2111d4b..377557f3 100644 --- a/templates/tailwindUI/dashboard.html +++ b/templates/tailwindUI/dashboard.html @@ -24,17 +24,34 @@

Posts

class="hover:text-rose-500 duration-150 font-medium" > + {% if recaptcha %} + + +
+ + + +
+ {% else %}
+ {% endif %}