]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Add function automatic logout
authorTomas Prochazka <tomas.prochazka@cvut.cz>
Tue, 14 Aug 2018 07:47:57 +0000 (09:47 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Tue, 14 Aug 2018 18:28:53 +0000 (20:28 +0200)
If the user makes a coffee, the user will logout automatically in 10 second.

templates/main.js
templates/user.html

index 11320ef87655aa310e31a418ebf749698dfafd15..5416627e1105d36e1b1789690c5dbe1bef5c9bd8 100644 (file)
@@ -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;
index 94c5d533c775d46e69905903d4d2e881d6d58640..4e3725f33090d85ca170aa06c3b6d1054fa78a81 100644 (file)
@@ -1,6 +1,6 @@
 {% if name %}
     <form style="position: absolute; right: 15%; width: 15%; height: 15%;">
-        <input type="button" value="logout" onclick="logout()" style="width: 100%; height: 100%;">
+        <input type="button" value="logout" id="logout_button" onclick="logout()" style="width: 100%; height: 100%;">
     </form>
 
     <h1>Hello, {{ name }}!</h1>
@@ -23,7 +23,6 @@
         </form>
         {% endif %}
     </p>
-
     <p>
         <form>
             <input id="username" type="text" name="name">