aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-23 23:39:15 +0000
committerAdam Soltys <[email protected]>2023-11-23 23:39:19 +0000
commit3d38a3656103b117fe1e68fa23aca3c1410fa969 (patch)
tree36439ccee411ff8da6699f5ab160d1399065361c /routes
parentab44bc3815c233a16586eada624672ff03e51224 (diff)
downloadcoinos-server-3d38a3656103b117fe1e68fa23aca3c1410fa969.tar.gz
coinos-server-3d38a3656103b117fe1e68fa23aca3c1410fa969.zip
new printer endpoints
Diffstat (limited to 'routes')
-rw-r--r--routes/users.js44
1 files changed, 28 insertions, 16 deletions
diff --git a/routes/users.js b/routes/users.js
index 187ffa2e..3270e2a9 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -9,7 +9,7 @@ import {
wait,
bail,
fail,
- getUser
+ getUser,
} from "$lib/utils";
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
@@ -98,7 +98,7 @@ export default {
username: key,
display: key.substr(0, 6),
pubkey: key,
- anon: true
+ anon: true,
};
}
@@ -116,7 +116,7 @@ export default {
"pubkey",
"display",
"prompt",
- "id"
+ "id",
];
if (user.pubkey)
@@ -141,7 +141,7 @@ export default {
pubkey,
password,
username,
- salt
+ salt,
};
user = await register(user, ip, false);
@@ -194,7 +194,7 @@ export default {
newpin,
username,
shopifyToken,
- shopifyStore
+ shopifyStore,
} = body;
if (user.pin && !(pin === user.pin)) throw new Error("Pin required");
@@ -236,7 +236,7 @@ export default {
"tokens",
"twofa",
"shopifyToken",
- "shopifyStore"
+ "shopifyStore",
];
for (let a of attributes) {
@@ -284,7 +284,7 @@ export default {
if (!token) fail();
user = await got(`${classic}/admin/migrate/${username}?zero=true`, {
- headers: { authorization: `Bearer ${config.admin}` }
+ headers: { authorization: `Bearer ${config.admin}` },
}).json();
let { balance } = user;
@@ -297,7 +297,7 @@ export default {
id: uid,
about: user.address,
migrated: true,
- haspin: !!user.pin
+ haspin: !!user.pin,
};
await s(`user:${username}`, uid);
@@ -305,7 +305,7 @@ export default {
await s(`balance:${uid}`, balance);
let payments = await got(`${classic}/payments`, {
- headers: { authorization: `Bearer ${token}` }
+ headers: { authorization: `Bearer ${token}` },
}).json();
for (let p of payments) {
@@ -315,7 +315,7 @@ export default {
"confirmed",
"rate",
"currency",
- "preimage"
+ "preimage",
]);
n.id = v4();
n.created = parseISO(p.createdAt).getTime();
@@ -333,7 +333,7 @@ export default {
u = await got(
`${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
{
- headers: { authorization: `Bearer ${config.admin}` }
+ headers: { authorization: `Bearer ${config.admin}` },
}
).json();
@@ -401,7 +401,7 @@ export default {
if (!subscriptions) subscriptions = [];
if (
!subscriptions.find(
- s => JSON.stringify(s) === JSON.stringify(subscription)
+ (s) => JSON.stringify(s) === JSON.stringify(subscription)
)
)
subscriptions.push(subscription);
@@ -439,8 +439,10 @@ export default {
let contacts = (await g(`${id}:contacts`)) || [];
for (let { ref } of (
- await Promise.all(payments.reverse().map(async id => await g(`payment:${id}`)))
- ).filter(p => p.type === types.internal && p.ref)) {
+ await Promise.all(
+ payments.reverse().map(async (id) => await g(`payment:${id}`))
+ )
+ ).filter((p) => p.type === types.internal && p.ref)) {
if (!~contacts.findIndex(({ id }) => id === ref)) {
contacts.unshift(await g(`user:${ref}`));
}
@@ -448,7 +450,7 @@ export default {
await s(`${id}:contacts`, contacts);
- res.send(contacts.map(u => pick(u, fields)));
+ res.send(contacts.map((u) => pick(u, fields)));
},
async del({ params: { username }, headers: { authorization } }, res) {
@@ -492,5 +494,15 @@ export default {
} catch (e) {
bail(res, e.message);
}
- }
+ },
+
+ async acl({ body: { username, topic } }, res) {
+ if (username === topic) res.send({ ok: true });
+ else bail(res, "unauthorized");
+ },
+
+ async superuser({ body: { username } }, res) {
+ if (username === config.mqtt.username) res.send({ ok: true });
+ else bail(res, "unauthorized");
+ },
};