diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2022-08-29 10:45:26 +0200 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2022-08-29 10:45:26 +0200 |
commit | 0116c966d3d6ea914ec4b9e3e5ec6e405d37f22d (patch) | |
tree | 27f515e059e4dbe16615eaf846a0ddb95232a5fd /server.js | |
parent | a3bdfe58867d57b39cf139fe7134c020fc9dcb44 (diff) |
login
Diffstat (limited to 'server.js')
-rwxr-xr-x | server.js | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -145,27 +145,40 @@ io.on("connection", socket => { } console.log(`new socket connection id=${socket_id} (nc=${num_connected})`); + let logged_in = false; + socket.on("disconnect", () => { num_connected--; console.log(`disconnect id=${socket_id} (nc=${num_connected})`); }); + socket.on("login", pass => { + if (pass == fs.readFileSync(__dirname + "/password.txt").toString().trim()) { + console.log(`login id=${socket_id}`); + logged_in = true; + socket.emit("init", database.get()); + } else { + socket.emit("unauth"); + } + }); + socket.on("new", string => { + if (!logged_in) { socket.emit("unauth"); return; } const res = database.add_new(string); if (res != null) socket.emit("error", res); }); socket.on("set_votes", (string, votes) => { + if (!logged_in) { socket.emit("unauth"); return; } const res = database.set_votes(string, votes); if (res != null) socket.emit("error", res); }); socket.on("delete", string =>{ + if (!logged_in) { socket.emit("unauth"); return; } const res = database.remove(string); if (res != null) socket.emit("error", res); }); - - socket.emit("init", database.get()); }); |