summaryrefslogtreecommitdiff
path: root/server/hornchat.authentication.token.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-10 10:38:44 +0200
committerMinteck <contact@minteck.org>2022-08-10 10:38:44 +0200
commitc6dbf0450566c40efc4a26f4f0717452b6ef95cd (patch)
treeb4be2d508223820d0a77d5a3e35e82684da3b6ec /server/hornchat.authentication.token.js
downloadhornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.tar.gz
hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.tar.bz2
hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.zip
Initial commitHEADmane
Diffstat (limited to 'server/hornchat.authentication.token.js')
-rw-r--r--server/hornchat.authentication.token.js34
1 files changed, 34 insertions, 0 deletions
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