diff options
| author | Adam Soltys <[email protected]> | 2023-03-27 21:09:22 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-27 21:09:22 -0700 |
| commit | 0559a382066722b794e1aaaafbb24266c7302f9e (patch) | |
| tree | ac390cb5f44f1d878f72760c89d8ee01f583e939 /routes/users.js | |
| parent | 5756d04533a69d93091dcbb469d83da6b55456bc (diff) | |
| download | coinos-server-0559a382066722b794e1aaaafbb24266c7302f9e.tar.gz coinos-server-0559a382066722b794e1aaaafbb24266c7302f9e.zip | |
strip spaces from usernames
Diffstat (limited to 'routes/users.js')
| -rw-r--r-- | routes/users.js | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/routes/users.js b/routes/users.js index 3c083d17..780d4003 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,7 +1,16 @@ import { g, s, db } from "$lib/db"; import config from "$config"; import store from "$lib/store"; -import { fields, nada, pick, uniq, wait, bail, fail } from "$lib/utils"; + import { + fields, + nada, + pick, + uniq, + wait, + bail, + fail, + getUser +} from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; import { authenticator } from "otplib"; @@ -83,7 +92,7 @@ export default { username: key, display: key.substr(0, 6), pubkey: key, - anon: true, + anon: true }; } @@ -100,7 +109,7 @@ export default { "pubkey", "display", "prompt", - "id", + "id" ]; if (user.pubkey) @@ -124,7 +133,7 @@ export default { pubkey, password, username, - salt, + salt }; user = await register(user, ip, false); @@ -175,7 +184,7 @@ export default { if (!user.pin || user.pin === "undefined") delete user.pin; let exists; - if (username) exists = await g(`user:${username.toLowerCase()}`); + if (username) exists = await getUser(username); let token; if (user.username.toLowerCase() !== username.toLowerCase() && exists) { @@ -201,7 +210,7 @@ export default { "salt", "seed", "tokens", - "twofa", + "twofa" ]; for (let a of attributes) { @@ -232,7 +241,7 @@ export default { username = username.toLowerCase().replace(/\s/g, ""); let uid = await g(`user:${username}`); - let user = await g(`user:${uid}`); + let user = await getUser(username); if (classic && !(user && user.migrated)) { uid = user ? user.id : v4(); @@ -245,7 +254,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; @@ -257,7 +266,7 @@ export default { ...pick(user, fields), id: uid, about: user.address, - migrated: true, + migrated: true }; await s(`user:${username}`, uid); @@ -265,7 +274,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) { @@ -275,7 +284,7 @@ export default { "confirmed", "rate", "currency", - "preimage", + "preimage" ]); n.id = v4(); n.created = parseISO(p.createdAt).getTime(); @@ -293,7 +302,7 @@ export default { u = await got( `${classic}/admin/migrate/${p.with.username.toLowerCase()}`, { - headers: { authorization: `Bearer ${config.admin}` }, + headers: { authorization: `Bearer ${config.admin}` } } ).json(); @@ -365,7 +374,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); @@ -402,8 +411,8 @@ export default { let contacts = (await g(`${id}:contacts`)) || []; for (let { ref } of ( - await Promise.all(payments.map(async (id) => await g(`payment:${id}`))) - ).filter((p) => p.type === types.internal && p.ref)) { + await Promise.all(payments.map(async id => await g(`payment:${id}`))) + ).filter(p => p.type === types.internal && p.ref)) { !~contacts.findIndex(({ id }) => id === ref) && contacts.push(await g(`user:${ref}`)); } @@ -419,7 +428,7 @@ export default { return res.code(401).send("unauthorized"); let { id, pubkey } = await g( - `user:${await g(`user:${username.toLowerCase()}`)}` + `user:${await g(`user:${username.replace(/\s/g, "").toLowerCase()}`)}` ); let invoices = await db.lRange(`${id}:invoices`, 0, -1); let payments = await db.lRange(`${id}:payments`, 0, -1); @@ -461,5 +470,5 @@ export default { } catch (e) { bail(res, e.message); } - }, + } }; |
