location -> loginLocations

This commit is contained in:
Girish Ramakrishnan
2021-04-30 10:07:04 -07:00
parent 44027f61e6
commit 6fe8974a2d
4 changed files with 16 additions and 18 deletions

View File

@@ -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);