const authenticator = require("otplib").authenticator; const axios = require("axios"); const bcrypt = require("bcrypt"); register = ah(async (user, ip, requireChallenge) => { if (!(user && user.username)) throw new Error("Username required"); let exists = await db.User.count({ where: { username: user.username } }); if (exists) throw new Error(`Username ${user.username} taken`); if (user.password) { user.password = await bcrypt.hash(user.password, 1); } let countries = { CA: "CAD", US: "USD", JP: "JPY", CN: "CNY", AU: "AUD", GB: "GBP", }; if (!config.ipstack || ip.startsWith("127") || ip.startsWith("192")) user.currency = "CAD"; else { let info = await axios.get( `http://api.ipstack.com/${ip}?access_key=${config.ipstack}` ); user.currency = countries[info.data.country_code] || "USD"; } user.currencies = [...new Set([user.currency, "CAD", "USD"])]; user.fiat = false; user.otpsecret = authenticator.generateSecret(); user = await db.User.create(user); let account = await db.Account.create({ user_id: user.id, asset: config.liquid.btcasset, balance: 0, pending: 0, name: "Bitcoin", ticker: "BTC", precision: 8, }); user.accounts = [account]; const d = ip.split("."); const numericIp = ((+d[0] * 256 + +d[1]) * 256 + +d[2]) * 256 + +d[3]; if (Number.isInteger(numericIp)) { user.ip = numericIp; const ipExists = await db.User.findOne({ where: { ip: numericIp } }); } user.account_id = account.id; await user.save(); l.info("new user", user.username, ip); return user; }); coinosv3.git/stats/bun.lock'>stats
path: root/bun.lock
blob: 658bc63e86a040a13bbe949f649eb24afbb4fd11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138