-
Jonas Leder authoredJonas Leder authored
deletelink.py 1.20 KiB
from sqlite3 import connect
from flask import redirect, abort
def deleteLink(request, s):
try:
userID = s.loads(request.cookies.get('userID')) #get the userid from the cookie
loginbar = "Hello " + s.loads(request.cookies.get('username')) + ' (<a href="/user/logout" style="color:white">logout</a>)' # generate the login form
loginbar = loginbar + "" #to hide the unused variable message
except:
abort(404) #if the user is not logged in, hide this page and return not found
linkToDelete = request.args.get('link') #get the link, which the user want's to delete from the parameter in the url.
with connect('db/urls.db') as conn:
cursor = conn.cursor()
try:
cursor.execute('DELETE FROM WEB_URL WHERE SHORT_URL=? AND USERNAME=?', [linkToDelete, userID]) #Delete the mapping
cursor.execute('DELETE FROM ANALYTICS WHERE SHORT_URL=?', [linkToDelete]) #Delete the statistics
return "OK" #response is only for ajax request
except:
abort(500) #return internal server error, if something fails
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()