Update user.js

This commit is contained in:
Troplo 2022-07-30 19:11:13 +10:00
parent a30ddb8fe3
commit ac1e9536e3

View file

@ -61,7 +61,7 @@ router.post("/login", async (req, res, next) => {
const ua = UAParser(req.headers["user-agent"]) const ua = UAParser(req.headers["user-agent"])
let ip = {} let ip = {}
await axios await axios
.get("http://ip-api.com/json/ " + req.header("x-real-ip") || req.ip) .get("http://ip-api.com/json/ " + req.ip)
.then((res) => { .then((res) => {
ip = res.data ip = res.data
}) })
@ -71,7 +71,7 @@ router.post("/login", async (req, res, next) => {
session: "COLUBRINA-" + cryptoRandomString({ length: 128 }), session: "COLUBRINA-" + cryptoRandomString({ length: 128 }),
expiredAt: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30), expiredAt: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30),
other: { other: {
ip: req.header("x-real-ip") || req.ip, ip: req.ip,
location: ip.country location: ip.country
? `${ip.city} - ${ip.regionName} - ${ip.country}` ? `${ip.city} - ${ip.regionName} - ${ip.country}`
: null, : null,
@ -150,7 +150,7 @@ router.post("/register", async (req, res, next) => {
const ua = UAParser(req.headers["user-agent"]) const ua = UAParser(req.headers["user-agent"])
let ip = {} let ip = {}
await axios await axios
.get("http://ip-api.com/json/ " + req.header("x-real-ip") || req.ip) .get("http://ip-api.com/json/ " + req.ip)
.then((res) => { .then((res) => {
ip = res.data ip = res.data
}) })
@ -160,7 +160,7 @@ router.post("/register", async (req, res, next) => {
session: "COLUBRINA-" + cryptoRandomString({ length: 128 }), session: "COLUBRINA-" + cryptoRandomString({ length: 128 }),
expiredAt: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30), expiredAt: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30),
other: { other: {
ip: req.header("x-real-ip") || req.ip, ip: req.ip,
location: ip.country location: ip.country
? `${ip.city} - ${ip.regionName} - ${ip.country}` ? `${ip.city} - ${ip.regionName} - ${ip.country}`
: null, : null,