diff options
| author | Adam Soltys <[email protected]> | 2020-06-13 21:39:22 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-06-13 21:39:22 -0700 |
| commit | 74b7d2a0d614f170ba5aea3a1a172a7a68356d80 (patch) | |
| tree | be2a73a9917616c0b49c24dc99642378e5a47549 /routes/users.js | |
| parent | dcb21adb40a44c8108f1d652cc6ddd59ae7c4024 (diff) | |
| download | coinos-server-74b7d2a0d614f170ba5aea3a1a172a7a68356d80.tar.gz coinos-server-74b7d2a0d614f170ba5aea3a1a172a7a68356d80.zip | |
push notifications
Diffstat (limited to 'routes/users.js')
| -rw-r--r-- | routes/users.js | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/routes/users.js b/routes/users.js index fc2f2975..9de84b83 100644 --- a/routes/users.js +++ b/routes/users.js @@ -101,7 +101,10 @@ app.post("/register", async (req, res) => { let ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress; - if (!challenge[ip] || user.response.toLowerCase() !== challenge[ip].toLowerCase()) { + if ( + !challenge[ip] || + user.response.toLowerCase() !== challenge[ip].toLowerCase() + ) { l.info("failed challenge", ip, user.response, challenge[ip]); return res.status(500).send("Failed challenge"); } @@ -203,7 +206,8 @@ app.post("/user", auth, async (req, res) => { twofa, pin, password, - passconfirm + passconfirm, + tokens } = req.body; let exists = await db.User.findOne({ @@ -231,6 +235,7 @@ app.post("/user", auth, async (req, res) => { user.currency = currency; user.currencies = currencies; + user.tokens = tokens; user.twofa = twofa; user.pin = pin; @@ -290,6 +295,19 @@ app.post("/login", async (req, res) => { } }); + +app.post("/logout", auth, async (req, res) => { + let { subscription } = req.body; + l.info("logging out", req.user.username); + if (!subscription) return res.end(); + let i = req.user.subscriptions.findIndex(s => JSON.stringify(s) === subscription); + if (i > -1) { + req.user.subscriptions.splice(i, 1); + } + await req.user.save(); + res.end(); +}); + app.post("/address", auth, async (req, res) => { if (!config.bitcoin) return res.status(500).send("Bitcoin not configured"); @@ -363,3 +381,22 @@ app.post("/shiftAccount", auth, async (req, res) => { }); setInterval(() => (faucet = 2000), DAY); + +app.get("/vapidPublicKey", function(req, res) { + res.send(config.vapid.publicKey); +}); + +app.post("/subscribe", auth, async function(req, res) { + let { subscriptions } = req.user; + let { subscription } = req.body; + if (!subscriptions) subscriptions = []; + if ( + !subscriptions.find(s => JSON.stringify(s) === JSON.stringify(subscription)) + ) + subscriptions.push(subscription); + req.user.subscriptions = subscriptions; + l.info("subscribing", req.user.username); + await req.user.save(); + res.sendStatus(201); +}); + |
