aboutsummaryrefslogtreecommitdiffstats
path: root/postcss.config.cjs
blob: 054c147cbf4a4e53873924b7120b5415853b1ed6 (plain) (blame)
1
2
3
4
5
6
module.exports = {
	plugins: {
		tailwindcss: {},
		autoprefixer: {}
	}
};
lor: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
import countries from "$lib/countries";
import config from "$config";
import { authenticator } from "otplib";
import bcrypt from "bcrypt";
import { l, warn } from "$lib/logging";
import { v4 } from "uuid";
import { s, g } from "$lib/db";
import { got } from "got";

export default async (user, ip, requireChallenge) => {
  let { password, pubkey, username } = user;
  l("registering", username);

  if (!username) throw new Error("Username required");

  username = username.replace(/ /g, "").toLowerCase();
  let id = v4();
  user.id = id;

  let exists = await g(`user:${username}`);
  if (exists) throw new Error(`Username ${username} taken`);

  if (password) {
    user.password = await bcrypt.hash(password, 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;

  let d = ip.split(".");
  ip = ((+d[0] * 256 + +d[1]) * 256 + +d[2]) * 256 + +d[3];
  if (Number.isInteger(ip)) {
    user.ip = ip;
  }

  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;
};