From c6dbf0450566c40efc4a26f4f0717452b6ef95cd Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 10 Aug 2022 10:38:44 +0200 Subject: Initial commit --- server/hornchat.authentication.token.js | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server/hornchat.authentication.token.js (limited to 'server/hornchat.authentication.token.js') diff --git a/server/hornchat.authentication.token.js b/server/hornchat.authentication.token.js new file mode 100644 index 0000000..dac9fcf --- /dev/null +++ b/server/hornchat.authentication.token.js @@ -0,0 +1,34 @@ +module.exports = (socket, data) => { + if (tokenFetchrateLimits[socket.ip] && new Date() - tokenFetchrateLimits[socket.ip] < 30000) { + socket.send(JSON.stringify({error:"RATE_LIMITED", success: false, device: null})); + console.log("[" + socket.id + "] IP address is being rate limited"); + tokenFetchrateLimits[socket.ip] = new Date(); + socket.close(); + return; + } + + if (userCredentials.filter((i) => i.id === data.username).length > 0) { + if (userCredentials.filter((i) => i.id === data.username)[0].devices) { + let tokens = userCredentials.filter((i) => i.id === data.username)[0].devices.map((i) => { + return i.token; + }); + + if (tokens.includes(data.token)) { + socket.send(JSON.stringify({error:null, success: true, device: null})); + } else { + socket.send(JSON.stringify({error:null, success: false, device: null})); + tokenFetchrateLimits[socket.ip] = new Date(); + } + + socket.close(); + } else { + socket.send(JSON.stringify({error:null, success: false, device: null})); + tokenFetchrateLimits[socket.ip] = new Date(); + socket.close(); + } + } else { + socket.send(JSON.stringify({error:null, success: false, device: null})); + tokenFetchrateLimits[socket.ip] = new Date(); + socket.close(); + } +} \ No newline at end of file -- cgit