From e45746fdec973e08ff1621cf0c441a79ee71b6a4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 6 Jul 2020 20:03:32 +0200 Subject: Initial implementation of a password prompt. --- src/ws/proto.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'src/ws/proto.js') diff --git a/src/ws/proto.js b/src/ws/proto.js index e4834b0..c94761e 100644 --- a/src/ws/proto.js +++ b/src/ws/proto.js @@ -107,6 +107,15 @@ try if(msg[0] == "error") { + if(msg[1] == "1" || // Bad username or password + msg[1] == "2") // Not authorized + { + // If there were a stored pw, it must be wrong, so reove the cookies + document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; + document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; + + loggedOut(); + } alert("Error(#" + unescape(msg[1]) + "): " + unescape(msg[2])); f++; continue; @@ -197,11 +206,27 @@ catch(exception) function transmit(msg) { - //LogEvent(msg); + var logmsg = msg; + + if(msg.match(/^login/g) != null) + { + // Don't show username and password in the log + logmsg = "login *** ***"; + loggedIn(); + } + + if(msg.match(/^logout/g) != null) + { + // If there were a stored pw, remove them to prevent auto-login + document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; + document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; + loggedOut(); + } + var messageEvent = new CustomEvent("messageEvent", { detail: { - message: "send [" + msg + "]", + message: "send [" + logmsg + "]", time: new Date(), }, bubbles: true, @@ -212,6 +237,26 @@ function transmit(msg) socket_node.send(msg); } +function loggedIn() +{ + var loggedInEvent = new CustomEvent("loggedInEvent", + { + bubbles: true, + cancelable: true + }); + document.dispatchEvent(loggedInEvent); +} + +function loggedOut() +{ + var loggedOutEvent = new CustomEvent("loggedOutEvent", + { + bubbles: true, + cancelable: true + }); + document.dispatchEvent(loggedOutEvent); +} + function login(user, password) { transmit("login "+user+" "+password); -- cgit v1.2.3