diff --git a/VERSION b/VERSION index 744068368fba2c75d14bfe4e589b0691d6c2835d..5ce8b3959987c922cc428a2c20909ee146d79187 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.0 \ No newline at end of file +1.18.1 \ No newline at end of file diff --git a/deletelink.py b/deletelink.py index f7213de798d96bdc4d9abbe8245db1c3f420f544..10f8250c62db5710c65f4f175ddd688874172e67 100644 --- a/deletelink.py +++ b/deletelink.py @@ -8,7 +8,8 @@ def deleteLink(request, s): 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. + linkToDelete = request.form.get('link') #get the link, which the user want's to delete from the parameter in the url. + print(linkToDelete) with connect('db/urls.db') as conn: cursor = conn.cursor() diff --git a/main.py b/main.py index 5ef70e402c235e6eb9fe34533df7b6cebf2fa2e6..ea69cc07739cc4fb224dbce9e26f77d054daa768 100644 --- a/main.py +++ b/main.py @@ -189,7 +189,7 @@ def ownLinks(pageNumber): if(loginEnabled): return userProfile(request, cookieNotice, s, pageNumber, url_scheme) else: abort(404) -@app.route('/user/delete') #This function is called if a user deletes an entrie +@app.route('/user/delete', methods=['POST']) #This function is called if a user deletes an entrie def delete(): if(loginEnabled): return deleteLink(request, s) else: abort(404) diff --git a/templates/editEntries.html b/templates/editEntries.html index e7df5e53afad4bcdfd9992566ae1c811bf1af539..6146e82e77448726b09d150fe1e97a0442b62a2f 100644 --- a/templates/editEntries.html +++ b/templates/editEntries.html @@ -43,25 +43,28 @@ } function deleteLink(link, elementId) { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var element = document.getElementById(elementId); - element.parentNode.removeChild(element); + if(confirm("Do you realy wan't to delete this")){ + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + var element = document.getElementById(elementId); + element.parentNode.removeChild(element); - var table = document.getElementById("t01"); - var rows = table.getElementsByTagName("tr").length - if(rows <= 1){ - var messageNoLinks = document.createElement('h2'); - messageNoLinks.innerHTML = 'you have no shorten links.'; - table.parentNode.replaceChild(messageNoLinks, table); + var table = document.getElementById("t01"); + var rows = table.getElementsByTagName("tr").length + if(rows <= 1){ + var messageNoLinks = document.createElement('h2'); + messageNoLinks.innerHTML = 'you have no shorten links.'; + table.parentNode.replaceChild(messageNoLinks, table); + } + }else if(this.readyState == 4) { + alert("error deleting link") } - }else if(this.readyState == 4) { - alert("error deleting link") - } - }; - xhttp.open("GET", link, true); - xhttp.send(); + }; + xhttp.open("POST", "/user/delete", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("link=" + link); + } } </script> </body> diff --git a/userprofile.py b/userprofile.py index c6e9a5e2fd8a7cce915741b813dcff8691b39959..e934afdaa7eb533ce22865acb0294048f0c09813 100644 --- a/userprofile.py +++ b/userprofile.py @@ -32,7 +32,7 @@ def userProfile(request, cookieNotice, s, pageNumber, url_scheme): calls = str(cursor2.execute('SELECT CALLS FROM ANALYTICS WHERE SHORT_URL=?', [entries[1]]).fetchone()[0]) except: calls = "0" - response = response + "<tr id=tr_" + str(idCounter) + ">\n<td>" + entries[0] + "</td>\n<td><a href=\"" + url_scheme + "://" + entries[1] + '">' + entries[1] + '</a></td>\n<td>' + calls + '</td>\n<td><a id="red" href="javascript:deleteLink(\'/user/delete?link=' + escape(entries[1].replace("'", "\\'")) + '\',\'tr_' + str(idCounter) + '\')">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n' + response = response + "<tr id=tr_" + str(idCounter) + ">\n<td>" + entries[0] + "</td>\n<td><a href=\"" + url_scheme + "://" + entries[1] + '">' + entries[1] + '</a></td>\n<td>' + calls + '</td>\n<td><a id="red" href="javascript:deleteLink(\'' + escape(entries[1].replace("'", "\\'")) + '\', \'tr_' + str(idCounter) + '\')">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n' idCounter=idCounter+1 response = response + "</table>" #Close the table