Fix failing tests
This commit is contained in:
+6
-4
@@ -537,11 +537,13 @@ function checkLoginLocation(user, ip, userAgent) {
|
||||
|
||||
debug(`checkLoginLocation: ${user.id} ${ip} ${userAgent}`);
|
||||
|
||||
superagent.get('https://geolocation.cloudron.io/json').query({ ip: ip }).end(function (error, result) {
|
||||
superagent.get('https://geolocation.cloudron.io/json').query({ ip }).end(function (error, result) {
|
||||
if (error) return console.error('Failed to get geoip info:', error);
|
||||
|
||||
const country = result.body.country.names.en;
|
||||
const city = result.body.city.names.en;
|
||||
const country = safe.query(result.body, 'country.names.en', '');
|
||||
const city = safe.query(result.body, 'city.names.en', '');
|
||||
|
||||
if (!city || !country) return;
|
||||
|
||||
const knownLogin = user.locations.find(function (l) {
|
||||
return l.userAgent === userAgent && l.country === country && l.city === city;
|
||||
@@ -551,7 +553,7 @@ function checkLoginLocation(user, ip, userAgent) {
|
||||
|
||||
// purge potentially old locations where ts > now() - 6 months
|
||||
const sixMonthsBack = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000;
|
||||
var locations = user.locations.filter(function (l) { return l.ts > sixMonthsBack; });
|
||||
let locations = user.locations.filter(function (l) { return l.ts > sixMonthsBack; });
|
||||
|
||||
locations.push({ ts: Date.now(), ip, userAgent, country, city });
|
||||
userdb.update(user.id, { locations }, function (error) {
|
||||
|
||||
Reference in New Issue
Block a user