aboutsummaryrefslogtreecommitdiffstats
path: root/lib/register.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-26 21:17:43 -0700
committerAdam Soltys <[email protected]>2024-08-26 21:17:43 -0700
commitfe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch)
treeaa8f34e1692bd2d638a2c996eeadb58671d07aea /lib/register.js
parent00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff)
downloadcoinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz
coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip
typescript
Diffstat (limited to 'lib/register.js')
-rw-r--r--lib/register.js62
1 files changed, 0 insertions, 62 deletions
diff --git a/lib/register.js b/lib/register.js
deleted file mode 100644
index 49111d96..00000000
--- a/lib/register.js
+++ /dev/null
@@ -1,62 +0,0 @@
-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 { l, warn } from "$lib/logging";
-import { fail, getUser } from "$lib/utils";
-
-let valid = /^[\p{L}\p{N}]{2,24}$/u;
-export default async (user, ip, requireChallenge) => {
- let { profile, password, pubkey, username } = user;
- l("registering", username);
-
- if (!username) fail("Username required");
- username = username.toLowerCase();
- if (!valid.test(username))
- fail("Usernames can only have letters and numbers");
-
- let id = v4();
- user.id = id;
-
- let exists = await getUser(username);
- if (exists) fail(`Username ${username} taken`);
-
- if (password) {
- user.password = await Bun.password.hash(password, {
- algorithm: "bcrypt",
- cost: 1,
- });
- }
-
- user.currency = "USD";
- if (config.ipregistry) {
- try {
- let {
- location: { country: { code } },
- } = await got(
- `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code`,
- ).json();
-
- user.currency = countries[code];
- } catch (e) {
- warn("unable to detect country from IP", username);
- }
- }
-
- user.currencies = [...new Set([user.currency, "CAD", "USD"])];
- user.fiat = false;
- user.otpsecret = authenticator.generateSecret();
- user.migrated = true;
- user.locktime = 300;
-
- await s(`user:${id}`, user);
- await s(`user:${username}`, id);
- await s(`user:${pubkey}`, id);
- await s(`balance:${id}`, 0);
-
- l("new user", username);
- return user;
-};