aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-03 21:25:52 +0000
committerAdam Soltys <[email protected]>2023-02-03 13:26:51 -0800
commitf4c51cddc3d6c45fa1de5fd928b1b2a0f95774f8 (patch)
tree911c6d2064b1ad386318c09435ab99ad054a9996
parent17a2a698de2a522f05d9ec813411b5a01b95234d (diff)
downloadcoinos-server-f4c51cddc3d6c45fa1de5fd928b1b2a0f95774f8.tar.gz
coinos-server-f4c51cddc3d6c45fa1de5fd928b1b2a0f95774f8.zip
delete user endpoint
-rw-r--r--index.js1
-rw-r--r--routes/nostr.js2
-rw-r--r--routes/payments.js18
-rw-r--r--routes/users.js20
4 files changed, 38 insertions, 3 deletions
diff --git a/index.js b/index.js
index ed4e0827..9e380334 100644
--- a/index.js
+++ b/index.js
@@ -69,6 +69,7 @@ app.post("/disable2fa", users.disable2fa);
app.post("/2fa", auth, users.enable2fa);
app.post("/user", auth, users.update);
app.post("/upload/:type", auth, users.upload);
+app.get('/users/delete/:username', users.del);
app.post("/login", users.login);
app.post("/logout", optional, users.logout);
diff --git a/routes/nostr.js b/routes/nostr.js
index 2900e949..005a4be9 100644
--- a/routes/nostr.js
+++ b/routes/nostr.js
@@ -44,7 +44,7 @@ export default {
let ids = await db.sMembers(pubkey);
let events = ids.length
- ? (await db.mget(ids.map(k => "ev:" + k))).map(JSON.parse)
+ ? (await db.mGet(ids.map(k => "ev:" + k))).map(JSON.parse)
: [];
res.send(events.map(e => ({ ...e, user })));
diff --git a/routes/payments.js b/routes/payments.js
index 970bc187..37f4c953 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -238,5 +238,21 @@ export default {
await bc.sendRawTransaction(hex);
res.send({ txid });
- }
+ },
+
+ async del({ params: { username }, headers: { authorization }}, res) {
+if (!authorization.includes(config.admin)) return res.code(401).send("unauthorized")
+ let { id, pubkey } = await g(`user:${await g(`user:${username}`)}`);
+ let invoices = await db.lRange(`${id}:invoices`, 0, -1);
+ let payments = await db.lRange(`${id}:payments`, 0, -1);
+
+ for (let {id} of invoices) db.del(`invoice:${id}`);
+ for (let {id} of payments) db.del(`payment:${id}`);
+ db.del(`user:${username}`);
+ db.del(`user:${id}`);
+ db.del(`user:${pubkey}`);
+
+ res.send({});
+ }
};
+
diff --git a/routes/users.js b/routes/users.js
index 10cc358d..4fcc50df 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -237,7 +237,8 @@ export default {
if (!p.with) continue;
let id = await g(`user:${p.with.username}`);
- let u = await g(`user:${id}`);
+ let u = id && await g(`user:${id}`);
+
if (!u) {
u = await got(`${classic}/admin/migrate/${p.with.username}`, {
headers: { authorization: `Bearer ${config.admin}` }
@@ -372,5 +373,22 @@ export default {
await s(`${id}:contacts`, contacts);
res.send(contacts);
+ },
+
+ async del({ params: { username }, headers: { authorization } }, res) {
+ if (!(authorization && authorization.includes(config.admin)))
+ return res.code(401).send("unauthorized");
+
+ let { id, pubkey } = await g(`user:${await g(`user:${username}`)}`);
+ let invoices = await db.lRange(`${id}:invoices`, 0, -1);
+ let payments = await db.lRange(`${id}:payments`, 0, -1);
+
+ for (let { id } of invoices) db.del(`invoice:${id}`);
+ for (let { id } of payments) db.del(`payment:${id}`);
+ db.del(`user:${username}`);
+ db.del(`user:${id}`);
+ db.del(`user:${pubkey}`);
+
+ res.send({});
}
};