From: Michal Sojka Date: Thu, 16 Aug 2018 09:46:55 +0000 (+0200) Subject: Improve the last commit X-Git-Url: https://rtime.felk.cvut.cz/gitweb/coffee/coffee-flask.git/commitdiff_plain/09105314174cdec5fba1e2a5b1bbfee5f69f4381 Improve the last commit - Move id_user variable to where other variables are defined and document it. - Set its value in the login() function. All other activities related to logging in are in that function, so I don't see a reason, why this should be outside. - Unset this variable in addCoffee() and logout(). We should not need it after these events. --- diff --git a/templates/main.js b/templates/main.js index 6d4fc86..daca42c 100644 --- a/templates/main.js +++ b/templates/main.js @@ -7,6 +7,7 @@ var loggedIn = false; // true after swiping the cards var timeToLogout = undefined; // defined during logout countdown var logoutTimer; var reloadTimer = undefined; +var id_user; // ID of the user who is to be accounted for the next coffee console.log("hello from flask"); //sendJSON("{\"type\":\"empty\"}"); @@ -63,8 +64,6 @@ function updateUI() } } -var id_user; - function hiddenUpdateRemote(json) { var msg = JSON.parse(json); @@ -82,7 +81,6 @@ function hiddenUpdateRemote(json) { "sak: " + msg.sak );*/ login(msg.uid); - id_user=msg.uid; break; case "keys": //update("json", "key: " + msg.key); @@ -159,6 +157,7 @@ function ajax(method, route, data, id) { function login(id) { ajax("POST", "login", id, "user"); loggedIn = true; + id_user = id; clearTimeout(logoutTimer); timeToLogout = undefined; } @@ -167,6 +166,7 @@ function logout() { sendReset(); ajax("GET", "logout", "", "user"); loggedIn = false; + id_user = undefined; timeToLogout = undefined; } @@ -205,6 +205,7 @@ function addCoffee(flavor) { ajax("POST", "coffee/add", data, "user"); flavorChosen = flavor; loggedIn = false; + id_user = undefined; countingTimeLogout(10); //mean 10 seconds } }