home » zplus/freepost.git
Author zPlus <zplus@peers.community> 2020-06-05 05:45:18
Committer zPlus <zplus@peers.community> 2020-06-05 05:45:18
Commit 9d3c76a (patch)
Tree 2ac3163
Parent(s)

Merge branch 'master' of https://notabug.org/zPlus/freepost.git * 'master' of https://notabug.org/zPlus/freepost.git: Add naive link duplication prevention


commits diff: 28af5ea..9d3c76a
2 files changed, 22 insertions, 0 deletionsdownload


Diffstat
-rwxr-xr-x freepost/__init__.py 3
-rw-r--r-- freepost/database.py 19

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+3/-0 M   freepost/__init__.py
index 8e18500..76da281
old size: 27K - new size: 27K
@@ -661,6 +661,9 @@ def submit_check ():
661 661 # If there is a URL, make sure it has a "scheme"
662 662 if len (link) > 0 and urlparse (link).scheme == '':
663 663 link = 'http://' + link
664 +
665 + if database.post_exists(link):
666 + return template ('submit.html', flash='Link has already been submitted.')
664 667
665 668 # Retrieve topics
666 669 topics = request.forms.getunicode ('topics')

+19/-0 M   freepost/database.py
index 1a88352..be03477
old size: 21K - new size: 21K
@@ -97,6 +97,25 @@ def username_exists (username, case_sensitive = True):
97 97
98 98 return cursor.fetchone() is not None
99 99
100 + # Check if post with same link exists
101 + def post_exists (link):
102 + if not link:
103 + return None
104 +
105 + with db:
106 + cursor = db.execute(
107 + """
108 + SELECT *
109 + FROM post
110 + WHERE LOWER(link) = LOWER(:link)
111 + """,
112 + {
113 + 'link': link
114 + }
115 + )
116 +
117 + return cursor.fetchone() is not None
118 +
100 119 # Create new user account
101 120 def new_user (username, password):
102 121 # Create a hash_id for the new post