diff --git a/frontend/website.py b/frontend/website.py index 85cef6e..4a5ea39 100644 --- a/frontend/website.py +++ b/frontend/website.py @@ -111,6 +111,7 @@ def confirmaccount(encoded_jwt): db.cur.execute("INSERT INTO user(email, pass_hashed, enabled) VALUES(?, ?, ?);", (uname, pass_hashed, 1)) db.conn.commit() bottle.response.set_cookie("account", uname, secret) + bottle.response.set_cookie("enabled", "True") return bottle.redirect("/settings") @@ -122,17 +123,43 @@ def manage_bot(): """ uname = bottle.request.get_cookie("account", secret=secret) if uname is not None: + db.cur.execute("SELECT enabled FROM user WHERE email=?;", (uname,)) + try: + enabled = db.cur.fetchone()[0] + except TypeError: + return "Wrong Credentials." # no user with this email + # Set Enable Status with a Cookie + if enabled: + bottle.response.set_cookie("enabled", "True") + else: + bottle.response.set_cookie("enabled", "False") return bottle.static_file("../static/bot.html", root='../static') else: bottle.abort(401, "Sorry, access denied.") -@app.route('/enable') +@app.route('/enable', method="POST") def enable(): + """ + Enable the bot. Called by the Enable button in bot.html + :return: redirect to settings page + """ email = bottle.request.get_cookie("account", secret=secret) - db.cur.execute("MODIFY user.enabled = 1 WHERE email=?;", (email)) # :todo is this correct SQL? + db.cur.execute("UPDATE user SET enabled = 1 WHERE email=?;", (email,)) # :todo is this correct SQL? db.conn.commit() - return bottle.static_file("../static/bot.html", root='../static') + bottle.response.set_cookie("enabled", "True") + return bottle.redirect("/settings") +@app.route('/disable', method="POST") +def disable(): + """ + Disable the bot. Called by the Disable button in bot.html + :return: redirect to settings page + """ + email = bottle.request.get_cookie("account", secret=secret) + db.cur.execute("UPDATE user SET enabled = 0 WHERE email=?;", (email,)) # :todo is this correct SQL? + db.conn.commit() + bottle.response.set_cookie("enabled", "False") + return bottle.redirect("/settings") @app.route('/static/') def static(filename): diff --git a/static/bot.html b/static/bot.html index 0d2eb5b..35a5202 100644 --- a/static/bot.html +++ b/static/bot.html @@ -11,14 +11,21 @@

Ticketfrei

-
- -
+
asdf
+ + + + + + + Log in with Twitter + + +
- \ No newline at end of file diff --git a/static/css/style.css b/static/css/style.css index 91be648..ae5e285 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -47,6 +47,16 @@ button { font-size: 120%; } +a.button { + background-color: #1da1f2; + color: white; + padding: 14px 20px; + margin: 8px 0; + border: none; + cursor: pointer; + font-size: 120%; +} + button:hover { opacity: 0.8; } @@ -71,8 +81,8 @@ input[type=text], input[type=password] { .footer { padding: 2em; bottom: 0; - text-align: center; - width: 540px; + float: center; + width: 240px; height: 30px; flex-shrink: 0; } \ No newline at end of file diff --git a/static/js/functions.js b/static/js/functions.js new file mode 100644 index 0000000..e1278fb --- /dev/null +++ b/static/js/functions.js @@ -0,0 +1,28 @@ +function enableButton() { + var enablebutton = '
'; + var disablebutton = '
'; + var enabled = getCookie('enabled'); + if (enabled == "True") { + return disablebutton; + } else { + return enablebutton; + } +} + +function getCookie(cname) { + var name = cname + '='; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; +} + +document.getElementById("enablebutton").innerHTML = enableButton();