From 46118ae9fa36a0646249effd4e7f238ef5c5f6a3 Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 2 Sep 2019 18:02:26 +1000 Subject: [PATCH] implemented bot deletion --- templates/bot_delete.html | 2 +- webui.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/templates/bot_delete.html b/templates/bot_delete.html index 6ecdc69..90986b8 100644 --- a/templates/bot_delete.html +++ b/templates/bot_delete.html @@ -12,7 +12,7 @@
-
+

Are you sure you want to permanently delete this bot?

diff --git a/webui.py b/webui.py index b7352e5..3881696 100644 --- a/webui.py +++ b/webui.py @@ -69,6 +69,7 @@ def show_signup_page(error = None): @app.route("/settings") def settings(): + return render_template("coming_soon.html") dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor) dc.execute("SELECT * FROM `users` WHERE id = %s", (session['user_id'],)) user = dc.fetchone() @@ -79,11 +80,23 @@ def settings(): def bot_edit(id): return render_template("bot_edit.html") -@app.route("/bot/delete/") +@app.route("/bot/delete/", methods=['GET', 'POST']) def bot_delete(id): if bot_check(id): - instance = id.split("@")[2] - return render_template("bot_delete.html", instance = instance) + if request.method == 'GET': + instance = id.split("@")[2] + return render_template("bot_delete.html", instance = instance) + else: + # delete bot by deleting its credentials + # FK constraint will delete bot + c = mysql.connection.cursor() + c.execute("SELECT `credentials_id` FROM `bots` WHERE `handle` = %s", (id,)) + credentials_id = c.fetchone()[0] + c.execute("DELETE FROM `credentials` WHERE `id` = %s", (credentials_id,)) + c.close() + mysql.connection.commit() + + return redirect(url_for("home"), 303) @app.route("/bot/toggle/") def bot_toggle(id):