Skip to content
Snippets Groups Projects
Commit 9ba4c4ee authored by Jonas Leder's avatar Jonas Leder
Browse files

added delete function

parent a0c81e45
No related branches found
No related tags found
No related merge requests found
Pipeline #47 passed
......@@ -135,7 +135,7 @@ def grecaptcha_verify(request): #This function is used to verify the google reca
@app.route('/', methods=['GET'])
def home_get():
try:
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/logout" style="color:white">logout</a>)'
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/links" style="color:white">your links</a>, <a href="/user/logout" style="color:white">logout</a>)'
except:
loginbar = '<a href="/user/login" style="color:white">login</a>'
......@@ -149,7 +149,7 @@ def home_post():
try:
userID = request.cookies.get('userID')
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/logout" style="color:white">logout</a>)'
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/links" style="color:white">your links</a>, <a href="/user/logout" style="color:white">logout</a>)'
except:
userID = "null"
loginbar = '<a href="/user/login" style="color:white">login</a>'
......@@ -248,13 +248,34 @@ def ownLinks():
res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE USERNAME=?', [userID])
response = '<table id="t01">\n<tr>\n<th>Long URL</th>\n<th>Short URL</th>\n<th>Action</th>\n</tr>\n'
try:
for entries in res.fetchall():
entriesList = res.fetchall()
for entries in entriesList:
response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td>" + entries[1] + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a></tr>\n'
if(len(entriesList) == 0): response = 'you have no shorten links. <a href="/">back</a>'
except:
abort(500)
response = response + "</table>"
return render_template('editEntries.html', content=response, loginbar=loginbar)
@app.route('/user/delete')
def delete():
try:
userID = request.cookies.get('userID')
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/logout" style="color:white">logout</a>)'
except:
return redirect("/user/login")
linkToDelete = request.args.get('link')
with sqlite3.connect('db/urls.db') as conn: #Get the original URL from the database
cursor = conn.cursor()
try:
cursor.execute('DELETE FROM WEB_URL WHERE SHORT_URL=? AND USERNAME=?', [linkToDelete, userID])
return redirect('/user/links')
except:
abort(500)
if __name__ == '__main__':
table_check()# This code checks whether database table is created or not
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment