diff options
| author | Adam Soltys <[email protected]> | 2024-01-09 23:10:35 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-01-09 23:10:39 -0800 |
| commit | 7a84d2555ffabbe29b23cf6e5035b6a4be8b9eb6 (patch) | |
| tree | 9fe2b7d523bbfe34176f115cb6823403fef1f802 /lib/register.js | |
| parent | e06878e18fc33e392fd16b76d1ab9f25f8bc7fbe (diff) | |
| download | coinos-server-7a84d2555ffabbe29b23cf6e5035b6a4be8b9eb6.tar.gz coinos-server-7a84d2555ffabbe29b23cf6e5035b6a4be8b9eb6.zip | |
remove users from archive once migrated
Diffstat (limited to 'lib/register.js')
| -rw-r--r-- | lib/register.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/register.js b/lib/register.js index a1489d89..b43a0ce7 100644 --- a/lib/register.js +++ b/lib/register.js @@ -1,26 +1,26 @@ -import countries from "$lib/countries"; -import config from "$config"; -import { authenticator } from "otplib"; import bcrypt from "bcrypt"; -import { l, warn } from "$lib/logging"; +import { got } from "got"; +import { authenticator } from "otplib"; import { v4 } from "uuid"; + +import config from "$config"; +import countries from "$lib/countries"; import { s, g, archive } from "$lib/db"; -import { got } from "got"; +import { l, warn } from "$lib/logging"; +import { fail, getUser } from "$lib/utils"; export default async (user, ip, requireChallenge) => { let { profile, password, pubkey, username } = user; l("registering", username); - if (!username) throw new Error("Username required"); + if (!username) fail("Username required"); username = username.replace(/ /g, "").toLowerCase(); let id = v4(); user.id = id; - let exists = - (await g(`user:${username}`)) || (await archive.get(`user:${username}`)); - - if (exists) throw new Error(`Username ${username} taken`); + let exists = await getUser(username); + if (exists) fail(`Username ${username} taken`); if (password) { user.password = await bcrypt.hash(password, 1); @@ -30,11 +30,9 @@ export default async (user, ip, requireChallenge) => { if (config.ipregistry) { try { let { - location: { - country: { code }, - }, + location: { country: { code } }, } = await got( - `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code` + `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code`, ).json(); user.currency = countries[code]; |
