From 1daf695b45c03511814f5cbc4b7ead1bbcfe9564 Mon Sep 17 00:00:00 2001 From: Tyler Engelhardt Date: Sun, 1 Sep 2019 01:21:45 -0400 Subject: [PATCH] Updated login, logout flow to update navbar --- management/daemon.py | 17 +++++++++++++++++ management/templates/login.html | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index 6e4a91f1..d0edc1d3 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -151,6 +151,23 @@ def me(): # Return. return json_response(resp) +@app.route('/logout') +def user_logout(): + global is_logged_in + + # Is the caller logged in? + if is_logged_in == True: + # User is now logged out + is_logged_in = False + return json_response({ + "status": "ok" + }) + + # Return. + return json_response({ + "status": "invalid" + }) + # MAIL @app.route('/mail/users') diff --git a/management/templates/login.html b/management/templates/login.html index b6e74df6..898cf1ab 100644 --- a/management/templates/login.html +++ b/management/templates/login.html @@ -117,7 +117,10 @@ function do_login() { // Open the next panel the user wants to go to. Do this after the XHR response // is over so that we don't start a new XHR request while this one is finishing, // which confuses the loading indicator. - setTimeout(function() { show_panel(!switch_back_to_panel || switch_back_to_panel == "login" ? 'system_status' : switch_back_to_panel) }, 300); + setTimeout(function() { + window.location = "/admin"; + show_panel(!switch_back_to_panel || switch_back_to_panel == "login" ? 'system_status' : switch_back_to_panel) + }, 300); } }) } @@ -128,7 +131,19 @@ function do_logout() { localStorage.removeItem("miab-cp-credentials"); if (typeof sessionStorage != 'undefined') sessionStorage.removeItem("miab-cp-credentials"); - show_panel('login'); + + api( + "/logout", + "GET", + {}, + function (response) { + // This API call always succeeds. It returns a JSON object + // with a status based on whether or not the user was actually logged in. + if (response.status == "ok") { + window.location = "/admin"; + show_panel('login'); + } + }) } function show_login() {