home » zplus/freepost.git
Author Nichlas Severinsen <ns@nsz.no> 2020-06-04 19:53:33
Committer Nichlas Severinsen <ns@nsz.no> 2020-06-04 19:53:33
Commit 3281c40 (patch)
Tree 3c05111
Parent(s)

Add naive link duplication prevention


commits diff: 7ee2c69..3281c40
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 29c8dfb..157c763
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