From 5cd96cc027be811116b147e0614aca39ce164c6b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 13 Jan 2021 15:46:53 -0800 Subject: account locking mechanism --- lib/sockets.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/sockets.js') 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": -- cgit v1.2.3