diff --git a/frontend/website.py b/frontend/website.py index e29a607..443142e 100644 --- a/frontend/website.py +++ b/frontend/website.py @@ -116,6 +116,8 @@ def confirm_account(encoded_jwt): with open(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "blacklists", "nbg_blacklist"), "r") as f: default_blacklist = f.read() + print(default_goodlist) # debug + print(default_blacklist) # debug db.cur.execute("INSERT INTO trigger_bad(user_id, words) VALUES(?, ?);", (get_user_id(email), default_blacklist)) db.conn.commit() bottle.response.set_cookie("account", email, secret, path="/") @@ -137,26 +139,29 @@ def manage_bot(): db.cur.execute("SELECT enabled FROM user WHERE email = ?;", (email,)) enabled = db.cur.fetchone()[0] # Set Enable Status with a Cookie + resp = bottle.static_file("../static/bot.html", root='../static') if enabled: - bottle.response.set_cookie("enabled", "True") + resp.set_cookie("enabled", "True") else: - bottle.response.set_cookie("enabled", "False") + resp.set_cookie("enabled", "False") # Get goodlist from db db.cur.execute("SELECT words FROM trigger_good WHERE user_id=?;", (user_id,)) words = db.cur.fetchone()[0] # Deliver goodlist with a Cookie print("setting goodlist cookies?") - bottle.response.set_cookie("goodlist", words, path="/settings") + resp.set_cookie("goodlist", words, path="/settings") + print(words) # debug # Get blacklist from db db.cur.execute("SELECT words FROM trigger_bad WHERE user_id=?;", (user_id,)) words = db.cur.fetchone()[0] # Deliver badlist with a Cookie print("setting blacklist cookies?") - bottle.response.set_cookie("blacklist", words, path="/settings") + resp.set_cookie("blacklist", words, path="/settings") + print(words) # debug - return bottle.static_file("../static/bot.html", root='../static') + return resp else: bottle.abort(401, "Wrong username or passphrase. Try again!") @@ -176,7 +181,7 @@ def update_goodlist(): """ # get new goodlist words = bottle.request.forms.get("goodlist") - user_id = get_user_id(bottle.cookie_decode("account", secret)) + user_id = get_user_id(bottle.request.get_cookie("account", secret=secret)) # write new goodlist to db db.cur.execute("UPDATE trigger_good SET words = ? WHERE user_id = ?;", (words, user_id, )) db.conn.commit() @@ -193,9 +198,7 @@ def update_blacklist(): # get new blacklist words = bottle.request.forms.get("blacklist") # get user_id - email = bottle.cookie_decode("account", secret) - db.cur.execute("SELECT id FROM user WHERE email = ?", (email, )) - user_id = db.cur.fetchone() + user_id = get_user_id(bottle.request.get_cookie("account", secret=secret)) # write new goodlist to db db.cur.execute("UPDATE trigger_bad SET words = ? WHERE user_id = ?;", (words, user_id, )) db.conn.commit() diff --git a/static/css/style.css b/static/css/style.css index ae5e285..f7400fd 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -82,7 +82,7 @@ input[type=text], input[type=password] { padding: 2em; bottom: 0; float: center; - width: 240px; + width: 540px; height: 30px; flex-shrink: 0; } \ No newline at end of file diff --git a/static/js/functions.js b/static/js/functions.js index 2eb45a3..ef1fa5c 100644 --- a/static/js/functions.js +++ b/static/js/functions.js @@ -25,11 +25,15 @@ function getCookie(cname) { return ""; } +function listformat(list) { + list = list.replace(/\"/g, '') + list = list.split('\\012'); + return list.join('\n'); +} + + document.getElementById("enablebutton").innerHTML = enableButton(); -// document.getElementById("goodlist").innerHTML = getCookie("goodlist"); +document.getElementById("goodlist").innerHTML = listformat(getCookie("goodlist")); -alert(getCookie("goodlist")) -alert(getCookie("blacklist")) - -// document.getElementById("blacklist").innerHTML = getCookie("blacklist"); \ No newline at end of file +document.getElementById("blacklist").innerHTML = listformat(getCookie("blacklist")); \ No newline at end of file