diff options
| author | Adam Soltys <[email protected]> | 2023-01-17 12:30:30 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-17 12:30:30 -0800 |
| commit | 5ae4209579287c571559edcf00dce24754553aaf (patch) | |
| tree | f897e334e3781345af66b11cd7a2b3b712912354 /routes | |
| parent | e918a818acf789a6619cbf4432f0c4713d4c53e6 (diff) | |
| download | coinos-server-5ae4209579287c571559edcf00dce24754553aaf.tar.gz coinos-server-5ae4209579287c571559edcf00dce24754553aaf.zip | |
rename db
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/nostr.js | 2 | ||||
| -rw-r--r-- | routes/users.js | 97 |
2 files changed, 44 insertions, 55 deletions
diff --git a/routes/nostr.js b/routes/nostr.js index 35b40c07..1cf9d595 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -1,7 +1,7 @@ import { nada, uniq } from "$lib/utils"; import config from "$config"; import { g, s, db } from "$lib/db"; -import { q } from "$lib/nostr"; +import { pool, q } from "$lib/nostr"; export default { async event({ params: { id } }, res) { diff --git a/routes/users.js b/routes/users.js index 53b02d02..c5ac61b1 100644 --- a/routes/users.js +++ b/routes/users.js @@ -117,69 +117,58 @@ export default { res.send({}); }, - async update( - { user, body: { confirm, password, pin, newpin, username } }, - res - ) { - try { - let { user } = req; + async update({ user, body }, res) { + l("updating user", user.username); - l("updating user", user.username); + let { confirm, password, pin, newpin, username } = body; - if (user.pin && !(pin === user.pin)) throw new Error("Pin required"); - if (typeof newpin !== "undefined") user.pin = newpin; - if (!user.pin) user.pin = null; + if (user.pin && !(pin === user.pin)) throw new Error("Pin required"); + if (typeof newpin !== "undefined") user.pin = newpin; + if (!user.pin) user.pin = null; - let exists; - if (username) exists = await g(`user:${username}`); + let exists; + if (username) exists = await g(`user:${username}`); - let token; - if (user.username !== username && exists) { - err("username taken", username, user.username, exists.username); - throw new Error("Username taken"); - } else if (username) { - if (user.username !== username) - l("changing username", user.username, username); - user.username = username; - } + let token; + if (user.username !== username && exists) { + err("username taken", username, user.username, exists.username); + throw new Error("Username taken"); + } else if (username) { + if (user.username !== username) + l("changing username", user.username, username); + user.username = username; + } - let attributes = [ - "address", - "cipher", - "currencies", - "currency", - "display", - "email", - "fiat", - "locktime", - "prompt", - "pubkey", - "salt", - "seed", - "tokens", - "twofa", - "unit" - ]; + let attributes = [ + "address", + "cipher", + "currencies", + "currency", + "display", + "email", + "fiat", + "locktime", + "prompt", + "pubkey", + "salt", + "seed", + "tokens", + "twofa", + ]; - for (let a of attributes) { - if (req.body[a]) user[a] = req.body[a]; - } - - if (password && password === confirm) { - user.password = await bcrypt.hash(password, 1); - } + for (let a of attributes) { + if (body[a]) user[a] = body[a]; + } - await s(`user:${user.id}`, user); + if (password && password === confirm) { + user.password = await bcrypt.hash(password, 1); + } - user.haspin = !!user.pin; + user.haspin = !!user.pin; + await s(`user:${user.id}`, user); - emit(user.username, "user", user); - res.send({ user, token }); - } catch (e) { - console.log(e); - err("error updating user", e.message); - res.code(500).send(e.message); - } + emit(user.username, "user", user); + res.send({ user, token }); }, async login(req, res) { |
