location -> loginLocations
This commit is contained in:
@@ -545,7 +545,7 @@ function checkLoginLocation(user, ip, userAgent) {
|
||||
|
||||
if (!city || !country) return;
|
||||
|
||||
const knownLogin = user.locations.find(function (l) {
|
||||
const knownLogin = user.loginLocations.find(function (l) {
|
||||
return l.userAgent === userAgent && l.country === country && l.city === city;
|
||||
});
|
||||
|
||||
@@ -553,10 +553,10 @@ function checkLoginLocation(user, ip, userAgent) {
|
||||
|
||||
// purge potentially old locations where ts > now() - 6 months
|
||||
const sixMonthsBack = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000;
|
||||
let locations = user.locations.filter(function (l) { return l.ts > sixMonthsBack; });
|
||||
let loginLocations = user.loginLocations.filter(function (l) { return l.ts > sixMonthsBack; });
|
||||
|
||||
locations.push({ ts: Date.now(), ip, userAgent, country, city });
|
||||
userdb.update(user.id, { locations }, function (error) {
|
||||
loginLocations.push({ ts: Date.now(), ip, userAgent, country, city });
|
||||
userdb.update(user.id, { loginLocations }, function (error) {
|
||||
if (error) console.error('checkLoginLocation: Failed to update user location.', error);
|
||||
|
||||
mailer.sendNewLoginLocation(user, ip, userAgent, country, city);
|
||||
|
||||
Reference in New Issue
Block a user