diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2020-07-06 20:03:32 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2020-07-06 20:06:46 +0200 |
commit | e45746fdec973e08ff1621cf0c441a79ee71b6a4 (patch) | |
tree | 4d00f51a013ab099bd9d130c3eba6be1548803d5 /src/ws/proto.js | |
parent | 236983125ffb300bb68bd5d56107750118e5fe96 (diff) |
Initial implementation of a password prompt.
Diffstat (limited to 'src/ws/proto.js')
-rw-r--r-- | src/ws/proto.js | 49 |
1 files changed, 47 insertions, 2 deletions
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); |