aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-07-08 10:17:45 -0700
committerAdam Soltys <[email protected]>2025-07-08 10:17:45 -0700
commit0ffadeb380f0f9bfec4b52f96ef5d362c1f3297b (patch)
tree7280f7ff00efbf923626d873a1c8ca282348f74b /routes
parentf5deb7da5b4f8cefa55c2dd7ac0fed1f11d827ad (diff)
downloadcoinos-server-0ffadeb380f0f9bfec4b52f96ef5d362c1f3297b.tar.gz
coinos-server-0ffadeb380f0f9bfec4b52f96ef5d362c1f3297b.zip
auto pay
Diffstat (limited to 'routes')
-rw-r--r--routes/users.ts53
1 files changed, 46 insertions, 7 deletions
diff --git a/routes/users.ts b/routes/users.ts
index 7f080cb9..b28d34c6 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -39,7 +39,7 @@ export default {
"blacklist",
user?.username?.toLowerCase().trim(),
);
-
+
const whitelisted = await db.sIsMember(
"whitelist",
user?.username?.toLowerCase().trim(),
@@ -195,9 +195,10 @@ export default {
if (user.id !== tokid) fail("unauthorized");
const { confirm, password, pin, newpin } = body;
- let username = body?.username?.toLowerCase().replace(/\s/g,"");
+ const username = body?.username?.toLowerCase().replace(/\s/g, "");
const valid = /^[\p{L}\p{N}]{2,24}$/u;
- if (!valid.test(username)) fail("Usernames can only have letters and numbers");
+ if (!valid.test(username))
+ fail("Usernames can only have letters and numbers");
let exists;
@@ -205,7 +206,9 @@ export default {
if (pubkey) {
pubkey = pubkey.trim();
exists = await getUser(pubkey);
- let existingUsername = exists.username.toLowerCase().replace(/\s/g,"");
+ const existingUsername = exists.username
+ .toLowerCase()
+ .replace(/\s/g, "");
if (exists && ![username].includes(existingUsername)) {
warn("key in use", pubkey, existingUsername);
if (exists.anon) await db.del(`user:${pubkey}`);
@@ -235,7 +238,7 @@ export default {
if (username) {
exists = await db.exists(`user:${username}`);
- let currentUsername = user.username.replace(/\s/g,"").toLowerCase()
+ const currentUsername = user.username.replace(/\s/g, "").toLowerCase();
if (currentUsername !== username && exists) {
err("username taken", username, currentUsername);
@@ -273,6 +276,7 @@ export default {
"shopifyStore",
"shopifyToken",
"threshold",
+ "tip",
"tokens",
"twofa",
];
@@ -281,6 +285,8 @@ export default {
if (typeof body[a] !== "undefined") user[a] = body[a];
}
+ user.tip = Math.max(0, Math.min(1000, parseInt(user.tip)));
+
if (password && password === confirm) {
user.password = await Bun.password.hash(password, {
algorithm: "bcrypt",
@@ -338,7 +344,7 @@ export default {
}
if (username !== "coinos")
- l("logged in", username, req.headers['cf-connecting-ip']);
+ l("logged in", username, req.headers["cf-connecting-ip"]);
const payload = { id: user.id };
const token = jwt.sign(payload, config.jwt);
@@ -394,7 +400,12 @@ export default {
}
const { username } = user;
- if (await db.sIsMember("compromised", username.replace(/\s/g,"").toLowerCase())) {
+ if (
+ await db.sIsMember(
+ "compromised",
+ username.replace(/\s/g, "").toLowerCase(),
+ )
+ ) {
warn("compromised nostr auth attempt");
fail("unauthorized");
}
@@ -490,6 +501,7 @@ export default {
let contacts = (await g(`${id}:contacts`)) || [];
const pins = await db.sMembers(`${id}:pins`);
+ const trust = await db.sMembers(`${id}:trust`);
for (const { ref } of (
await Promise.all(
@@ -514,6 +526,14 @@ export default {
c.pinned = true;
});
+ const trusted = contacts
+ .filter((c) => trust.includes(c.id))
+ .sort((a, b) => a.username.localeCompare(b.username));
+
+ trusted.map((c) => {
+ c.trusted = true;
+ });
+
let { limit } = params;
limit ||= contacts.length;
contacts = contacts.filter((c) => !pins.includes(c.id));
@@ -994,6 +1014,25 @@ export default {
res.send({});
},
+ async trust(req, res) {
+ const { id } = req.user;
+ res.send(await db.sMembers(`${id}:trust`));
+ },
+
+ async addTrust(req, res) {
+ const { id: uid } = req.user;
+ const { id } = req.body;
+ await db.sAdd(`${uid}:trust`, id);
+ res.send({});
+ },
+
+ async deleteTrust(req, res) {
+ const { id: uid } = req.user;
+ const { id } = req.body;
+ await db.sRem(`${uid}:trust`, id);
+ res.send({});
+ },
+
async credits(req, res) {
const { id } = req.user;
const bitcoin = await g(`credit:bitcoin:${id}`);