commit 3decd37d3f9c65980fe1805bc6975f95a543b2f5
parent 3b19045227bbb5012f1f804a7ed5f90227f04031
Author: knutsen <samuel@knutsen.co>
Date: Tue, 8 Jun 2021 22:53:55 +0100
Spam filtering.
Diffstat:
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/shiimoe.py b/shiimoe.py
@@ -68,6 +68,8 @@ def render_guestbook(**kw):
def guestbook():
return render_guestbook()
+LINK_MATCH = re.compile("https?://")
+
@app.route('/postcomment', methods=['POST'])
def postcomment():
now = datetime.now()
@@ -79,9 +81,21 @@ def postcomment():
request.environ.get('REMOTE_ADDR') or
request.remote_addr)
+ err = lambda msg: render_guestbook(error_msg=msg)
+
# Comment or name left empty, send error message.
if not (name or "").strip() or not (comment or "").strip():
- return render_guestbook(error_msg="Please provide a name and comment.")
+ return err("Please provide a name and comment.")
+
+ # Spam filtering!!
+ if len(name) > 130:
+ return err("You're taking the piss with a name that long mate.")
+ if len(comment) > 850:
+ return err("No more than 850 characters!")
+ if name.lower() == "annasysdek":
+ return err("Sorry, that name is toxic. Pick another.")
+ if len(LINK_MATCH.findall(comment)) > 2:
+ return err("No more than two (2) links!")
comments = read_comments()
comments.append({
diff --git a/templates/guestbook.html b/templates/guestbook.html
@@ -116,7 +116,7 @@
<input class="name-input input" name="name" placeholder="Your name" required>
<div class="textbox">
<textarea class="comment-input input" name="comment"
- placeholder="# Your comment

(≤2 links, ≤500 characters)"
+ placeholder="# Your comment

(≤2 links, ≤850 characters)"
required></textarea>
<i class="fab fa-markdown"></i>
</div>