diff --git a/main.py b/main.py index e1dbb96634e6651996d9ff01ecd533531a231253..6a1a900b8d841f1e5ad289983626ae4c082dccf0 100644 --- a/main.py +++ b/main.py @@ -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