aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sockets.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-01-13 15:46:53 -0800
committerAdam Soltys <[email protected]>2021-01-13 16:11:11 -0800
commit5cd96cc027be811116b147e0614aca39ce164c6b (patch)
treea9d7d9096bc4ea5bb7049500571e9641b50177d7 /lib/sockets.js
parenteb860d78b836d810f7c29d5587e17321adf20bef (diff)
downloadcoinos-server-5cd96cc027be811116b147e0614aca39ce164c6b.tar.gz
coinos-server-5cd96cc027be811116b147e0614aca39ce164c6b.zip
account locking mechanism
Diffstat (limited to 'lib/sockets.js')
-rw-r--r--lib/sockets.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sockets.js b/lib/sockets.js
index 1ed18610..25f8aed8 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -106,6 +106,7 @@ wss.on("connection", function(ws, req) {
names[id] = username;
let user = await getUser(username);
+ if (user.locked) throw new Error("Account is locked");
let payments = await user.getPayments({
where: {
account_id: user.account_id
@@ -131,9 +132,13 @@ wss.on("connection", function(ws, req) {
);
} catch (e) {
l.error("caught socket error", e.message);
+ if (e.message.includes("locked")) {
+ ws.send(JSON.stringify({ type: "locked" }));
+ ws.send(JSON.stringify({ type: "logout" }));
+ }
if (e.message.includes("not found"))
ws.send(JSON.stringify({ type: "logout" }));
- setTimeout(ws.close, 1000);
+ setTimeout(() => ws && ws.close(), 1000);
}
break;
case "token":