From 0116c966d3d6ea914ec4b9e3e5ec6e405d37f22d Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 29 Aug 2022 10:45:26 +0200 Subject: login --- static/index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'static/index.js') diff --git a/static/index.js b/static/index.js index 23d53ea..31099d6 100644 --- a/static/index.js +++ b/static/index.js @@ -6,11 +6,26 @@ var el_list = null; function setupSocket() { socket = io(); + document.getElementById("loginbtn").removeAttribute("disabled"); + + socket.on("unauth", function() { + document.body.classList.remove("okauth"); + document.body.classList.add("unauth"); + var span = document.createElement("span"); + var unauthlog = document.getElementById("unauthlog"); + span.appendChild(document.createTextNode("unauth received")); + unauthlog.appendChild(span); + setTimeout(function() { unauthlog.removeChild(span); }, 1500); + }); + socket.on("init", function(list) { // Reload if server restarted if (!is_initialised) is_initialised = true; else { location.reload(); return; } + document.body.classList.remove("unauth"); + document.body.classList.add("okauth"); + glist = list; for (var i = 0; i < glist.length; i++) glist[i].push(null); initialiseList(); @@ -190,7 +205,19 @@ function reinsertItem(index) { insertItem(votes, string); } +function doLogin() { + const password = document.getElementById("password").value; + socket.emit("login", password); +} + +function doPasswordKeypress(ev) { + if (ev.key == "Enter" || ev.keyCode == 10 || ev.keyCode == 13) { + doLogin(); + } +} + window.addEventListener("load", function() { el_list = document.getElementById("list"); setupSocket(); + document.getElementById("password").focus(); }); -- cgit v1.2.3-70-g09d2