Skip to content

Commit

Permalink
Custom CSRF error page added
Browse files Browse the repository at this point in the history
  • Loading branch information
DogukanUrker committed Dec 21, 2023
1 parent 79c09ee commit 72b388b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from routes.adminPanelComments import adminPanelCommentsBlueprint
from routes.changeProfilePicture import changeProfilePictureBlueprint
from dbChecker import dbFolder, usersTable, postsTable, commentsTable
from flask_wtf.csrf import CSRFProtect
from flask_wtf.csrf import CSRFProtect, CSRFError

dbFolder()
usersTable()
Expand All @@ -56,6 +56,11 @@ def notFound(e):
return render_template("404.html"), 404


@app.errorhandler(CSRFError)
def handle_csrf_error(e):
return render_template("csrfError.html", reason=e.description), 400


app.register_blueprint(postBlueprint)
app.register_blueprint(userBlueprint)
app.register_blueprint(indexBlueprint)
Expand Down
11 changes: 11 additions & 0 deletions templates/csrfError.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'layout.html'%} {%block head%}
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🔎</text></svg>"
/>
{% endblock head %} {%block body%}
<div class="errorMessage">
<h1>Fill the same form again.</h1>
<p>Reason: {{reason}}</p>
</div>
{% endblock body %}

0 comments on commit 72b388b

Please sign in to comment.