diff options
| -rw-r--r-- | res/client/css/partials/top-bar.scss | 6 | ||||
| -rw-r--r-- | res/client/css/style.css | 3 | ||||
| -rw-r--r-- | res/templates/index.html | 2 | ||||
| -rw-r--r-- | res/templates/login.html | 33 | ||||
| -rw-r--r-- | src/client/buttons.js | 15 | ||||
| -rw-r--r-- | 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 @@ <div class="username"> <div class="profile-circle"></div> <span class="profile-initials">AN<!-- must be two letters because of css --></span> - <div class="profile-username">Welcome <span id="user_id">Anonymous</span>! <span><form action="/logout" method="POST" class="logout-form"><input type="submit" value="Logout" class="button"></input></form></span></div> + <div class="profile-username">Welcome <span id="user_id">Anonymous</span>! <span id="logout-button" class="button">Logout</span></div> </div> <img class="organization-logo" src="/static/img/CRI-logo.png"> </div> 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 @@ <title>Welcome to Rhizi</title> <link href="/static/css/style.css" rel="stylesheet" type="text/css"> <script src="/static/lib/jquery.js" type="text/javascript"></script> +<script type="text/javascript"> + function submit_login_form() { + var data = { + username : $('#login_username').val(), + password : $('#login_password').val() + }; + + // TODO: validate + + $.ajax({ + type : "POST", + url: '/login', + async : false, + cache : false, + data : JSON.stringify(data), + dataType : 'json', + contentType : "application/json; charset=utf-8", + success : function () { + document.location = "/index"; + }, + error : function () { + document.location = "/login"; + } + }); + } +</script> </head> + <body class="login-background"> <div class="welcome-box"> <img src="/static/img/logo-red.png" class="login-rhizi-logo"> @@ -18,9 +45,9 @@ </div> <div id="login_form_panel" class="login-form"> <fieldset> - <form action="/login" method="POST" id="login_form"> - <input class="login-input" type="email" name="username" id="login-username" placeholder="Email"> - <input class="login-input" type="password" name="password" id="login-password" placeholder="Password" required value="Password"> + <form action="javascript:void(0);" method="get" onsubmit="submit_login_form();" id="login_form"> + <input class="login-input" type="email" id="login_username" placeholder="Email"> + <input class="login-input" type="password" id="login_password" placeholder="Password" required value="Password"> <input class="login-input" type="submit" value="Sign in"> <a class="forgot-password"> forgot password? </a> </form> 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') |
