From 9727204ed66ef0d6acfbf4df0bf49f5e4d9c10ba Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 12 Jan 2015 14:49:50 +0200 Subject: login+logout: using ajax, not POST, plus document.window (worst of both worlds) --- res/client/css/partials/top-bar.scss | 6 +----- res/client/css/style.css | 3 --- res/templates/index.html | 2 +- res/templates/login.html | 33 ++++++++++++++++++++++++++++++--- src/client/buttons.js | 15 +++++++++++++++ src/server/rz_api.py | 4 ++-- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/res/client/css/partials/top-bar.scss b/res/client/css/partials/top-bar.scss index 5aec704c..cffd200a 100644 --- a/res/client/css/partials/top-bar.scss +++ b/res/client/css/partials/top-bar.scss @@ -57,8 +57,4 @@ background: url(../img/CRI-logo.png); min-height: 30px; min-width: 30px; -} - -.logout-form { - display: inline; -} +} \ No newline at end of file diff --git a/res/client/css/style.css b/res/client/css/style.css index b4008d93..b6231384 100644 --- a/res/client/css/style.css +++ b/res/client/css/style.css @@ -826,9 +826,6 @@ body.debug .debug-ui-right { min-height: 30px; min-width: 30px; } -.logout-form { - display: inline; } - /* Headings */ h1 { font-size: 30px; } diff --git a/res/templates/index.html b/res/templates/index.html index 6ef39e25..13913ba2 100644 --- a/res/templates/index.html +++ b/res/templates/index.html @@ -23,7 +23,7 @@
AN -
Welcome Anonymous!
+
Welcome Anonymous! Logout
diff --git a/res/templates/login.html b/res/templates/login.html index 3e32eee3..57bbdec4 100644 --- a/res/templates/login.html +++ b/res/templates/login.html @@ -4,7 +4,34 @@ Welcome to Rhizi + +
@@ -18,9 +45,9 @@
-
- - + + + forgot password?
diff --git a/src/client/buttons.js b/src/client/buttons.js index 5fd8d121..dfd2c5f3 100644 --- a/src/client/buttons.js +++ b/src/client/buttons.js @@ -67,6 +67,21 @@ $('.local-storage-load a').click(function(){ rz_core.load_from_json(json_blob); }); +var logout_button = $('#logout-button'); +logout_button.click(function() { + $.ajax({ + type: "POST", + url: '/logout', + success: function () { + document.location = "/login"; + }, + error: function () { + console.log("failed to logout"); + document.location = "/login"; + }, + }); // server should redirect back to /login +}); + $('a.save-history').click(function() { if (rz_core.main_graph.history === undefined) { throw "History is undefined"; diff --git a/src/server/rz_api.py b/src/server/rz_api.py index fc2e2343..2a2500bb 100644 --- a/src/server/rz_api.py +++ b/src/server/rz_api.py @@ -170,7 +170,7 @@ def index(): def login(): def sanitize_input(req): - req_json = request.form.to_dict() + req_json = request.get_json() u = req_json['username'] p = req_json['password'] return u, p @@ -191,7 +191,7 @@ def login(): # login successful session['username'] = u log.debug('login: success: user: %s' % (u)) - return redirect('/index') + return '{}'; if request.method == 'GET': return render_template('login.html') -- cgit v1.3.1