diff --git a/freepost/__init__.py b/freepost/__init__.py index 8e18500..76da281 100755 --- a/freepost/__init__.py +++ b/freepost/__init__.py @@ -661,6 +661,9 @@ def submit_check (): # If there is a URL, make sure it has a "scheme" if len (link) > 0 and urlparse (link).scheme == '': link = 'http://' + link + + if database.post_exists(link): + return template ('submit.html', flash='Link has already been submitted.') # Retrieve topics topics = request.forms.getunicode ('topics') diff --git a/freepost/database.py b/freepost/database.py index 1a88352..be03477 100644 --- a/freepost/database.py +++ b/freepost/database.py @@ -97,6 +97,25 @@ def username_exists (username, case_sensitive = True): return cursor.fetchone() is not None +# Check if post with same link exists +def post_exists (link): + if not link: + return None + + with db: + cursor = db.execute( + """ + SELECT * + FROM post + WHERE LOWER(link) = LOWER(:link) + """, + { + 'link': link + } + ) + + return cursor.fetchone() is not None + # Create new user account def new_user (username, password): # Create a hash_id for the new post