From 7908ae2f48a7a3d654ee17530e7dae56d43b7e7d Mon Sep 17 00:00:00 2001 From: Tomas Prochazka Date: Tue, 14 Aug 2018 09:47:57 +0200 Subject: [PATCH] Add function automatic logout If the user makes a coffee, the user will logout automatically in 10 second. --- templates/main.js | 20 +++++++++++++++----- templates/user.html | 3 +-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/templates/main.js b/templates/main.js index 11320ef..5416627 100644 --- a/templates/main.js +++ b/templates/main.js @@ -28,12 +28,25 @@ function loadLocalStorage() { var flavorChosen; +function countingTimeLogout(count_time){ + document.getElementById("logout_button").value = 'Logout in \n(' + count_time + ' second)'; + if (count_time == 0){ + timer = setTimeout(logout, 100); + return; + } + setTimeout(function() { countingTimeLogout(count_time -1); }, 1000); +} + function updateNextStep() { if (loggedIn) { - document.getElementById("nextStep").innerHTML = "Now select a beverage on the coffee machine…"; + document.getElementById("nextStep").innerHTML = "Now select a beverage on the coffee machine…"; } else { - document.getElementById("nextStep").innerHTML = "Enjoy your " + flavorChosen + "!"; + if (flavorChosen !== undefined) { + document.getElementById("nextStep").innerHTML = "Enjoy your " + flavorChosen + "!"; + flavorChosen=undefined; + countingTimeLogout(10); //mean 10 seconds + } } } @@ -125,17 +138,14 @@ function ajax(method, route, data, id) { } } -//var timer; function login(id) { ajax("POST", "login", id, "user"); loggedIn = true; document.getElementById("local").style.display = "none"; - //timer = setTimeout(logout, 20000); } function logout() { - //clearTimeout(timer); sendReset(); ajax("GET", "logout", "", "user"); loggedIn = false; diff --git a/templates/user.html b/templates/user.html index 94c5d53..4e3725f 100644 --- a/templates/user.html +++ b/templates/user.html @@ -1,6 +1,6 @@ {% if name %}
- +

Hello, {{ name }}!

@@ -23,7 +23,6 @@ {% endif %}

-

-- 2.39.2