aboutsummaryrefslogtreecommitdiffstats
path: root/lib/register.js
diff options
context:
space:
mode:
authorJohn Barratt <[email protected]>2023-02-28 13:55:59 -0800
committerJohn Barratt <[email protected]>2023-02-28 13:55:59 -0800
commite47d50a443f0a396321716a506e1df325dd4a1fb (patch)
tree1c010c5970e9cbfbf8671e6f00a97d6518446fdd /lib/register.js
parent58e996a4ac227162f171e84530fe898cb504e045 (diff)
parente4702b4d13e4d966d735c2ba4657e10d7c436a57 (diff)
downloadcoinos-server-e47d50a443f0a396321716a506e1df325dd4a1fb.tar.gz
coinos-server-e47d50a443f0a396321716a506e1df325dd4a1fb.zip
Merge branch 'master' of https://github.com/coinos/coinos-server into notifications
Diffstat (limited to 'lib/register.js')
-rw-r--r--lib/register.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/register.js b/lib/register.js
index c55d2f9d..22c36b4c 100644
--- a/lib/register.js
+++ b/lib/register.js
@@ -2,7 +2,7 @@ import countries from "$lib/countries";
import config from "$config";
import { authenticator } from "otplib";
import bcrypt from "bcrypt";
-import { l } from "$lib/logging";
+import { l, warn } from "$lib/logging";
import { v4 } from "uuid";
import { s, g } from "$lib/db";
import { got } from "got";
@@ -17,7 +17,7 @@ export default async (user, ip, requireChallenge) => {
let id = v4();
user.id = id;
- let exists = await g(`user:${username}`);
+ let exists = await g(`user:${username.toLowerCase()}`);
if (exists) throw new Error(`Username ${username} taken`);
if (password) {
@@ -25,19 +25,20 @@ export default async (user, ip, requireChallenge) => {
}
user.currency = "USD";
- if (config.ipxapi) {
- let countryCode = "US";
-
+ if (config.ipregistry) {
try {
- let r = await got(`https://ipxapi.com/api/ip?ip=${ip}`, {
- headers: { authorization: `Bearer ${config.ipxapi}` }
- }).json();
- if (r.success) ({ countryCode } = r);
+ 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) {
- console.log(e);
+ warn("unable to detect country from IP", username);
}
-
- user.currency = countries[countryCode];
}
user.currencies = [...new Set([user.currency, "CAD", "USD"])];