diff options
Diffstat (limited to 'lib/register.ts')
| -rw-r--r-- | lib/register.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/register.ts b/lib/register.ts index 0db5dfd0..a9e9d7f7 100644 --- a/lib/register.ts +++ b/lib/register.ts @@ -2,7 +2,9 @@ import config from "$config"; import countries from "$lib/countries"; import { db, s } from "$lib/db"; import { l, warn } from "$lib/logging"; -import { fail, getUser } from "$lib/utils"; +import { fail } from "$lib/utils"; +import { assertNameFree } from "$lib/names"; +import { isReserved } from "$lib/reserved"; import { bytesToHex, randomBytes } from "@noble/hashes/utils"; import { got } from "got"; import { getPublicKey, nip19 } from "nostr-tools"; @@ -19,20 +21,26 @@ export default async (user, ip) => { username = username.toLowerCase().replace(/\s/g, ""); if (!valid.test(username)) fail("Usernames can only have letters and numbers"); + if (isReserved(username)) fail("Invalid username"); + if (username.includes("undefined")) fail("Invalid username"); const id = v4(); user.id = id; const exists = await db.exists(`user:${username}`); if (exists) fail(`Username ${username} taken`); + // A name the v3 registrar holds is taken too (see lib/names.ts). + await assertNameFree(username, pubkey); if (password) { user.password = await Bun.password.hash(password, { algorithm: "bcrypt", - cost: 4, + cost: 12, }); } + user.created = Date.now(); + user.currency = "USD"; if (config.ipregistry) { try { @@ -43,6 +51,7 @@ export default async (user, ip) => { ).json(); user.currency = countries[code]; + user.country = code; // stored for analytics (signup geography) } catch (e) { warn("unable to detect country from IP", username); } @@ -85,8 +94,6 @@ export default async (user, ip) => { await s(`app:${app.pubkey}`, app); await db.sAdd(`${id}:apps`, app.pubkey); - console.log("USER", user); - db.multi() .set(`user:${id}`, JSON.stringify(user)) .set(`user:${username}`, id) |
