aboutsummaryrefslogtreecommitdiff
path: root/src/invite.js
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-15 20:14:41 +0000
committerAkshay <[email protected]>2024-11-15 20:14:41 +0000
commitd4a83cb44dc98fe78f9061408137a43049344b1d (patch)
treed4314ce0b793150f6984a8f47f36f9695f3c0747 /src/invite.js
parente2c410822ad8aea8ec702cef6bba5de352b8c73d (diff)
add invite system
Diffstat (limited to 'src/invite.js')
-rw-r--r--src/invite.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/invite.js b/src/invite.js
new file mode 100644
index 0000000..0f6624c
--- /dev/null
+++ b/src/invite.js
@@ -0,0 +1,37 @@
1const { db } = require("./db");
2
3const validateInviteToken = async (req, res, next) => {
4 const token = req.query.token;
5
6 if (!token) {
7 return res.render("register", {
8 message: "this instance requires an invite",
9 isDisabled: true,
10 });
11 }
12
13 const invite = db
14 .query("SELECT * FROM invites WHERE token = $token AND usedAt IS null")
15 .get({ token });
16
17 if (!invite) {
18 return res.render("register", {
19 message: "this invite token is invalid",
20 isDisabled: true,
21 });
22 }
23
24 if (invite.usedAt) {
25 return res.render("register", {
26 message: "this invite has been claimed",
27 isDisabled: true,
28 });
29 }
30
31 req.invite = invite;
32 next();
33};
34
35module.exports = {
36 validateInviteToken,
37};