Fallback to unkown useragent and don't stash such login attempts
This commit is contained in:
@@ -547,7 +547,7 @@ function checkLoginLocation(user, ip, userAgent) {
|
||||
if (!city || !country) return;
|
||||
|
||||
const ua = uaParser(userAgent);
|
||||
const simplifiedUserAgent = ua.browser.name + ' - ' + ua.os.name;
|
||||
const simplifiedUserAgent = ua.browser.name ? `${ua.browser.name} - ${ua.os.name}` : '';
|
||||
|
||||
const knownLogin = user.loginLocations.find(function (l) {
|
||||
return l.userAgent === simplifiedUserAgent && l.country === country && l.city === city;
|
||||
@@ -560,7 +560,9 @@ function checkLoginLocation(user, ip, userAgent) {
|
||||
const newLoginLocation = { ts: Date.now(), ip, userAgent: simplifiedUserAgent, country, city };
|
||||
let loginLocations = user.loginLocations.filter(function (l) { return l.ts > sixMonthsBack; });
|
||||
|
||||
loginLocations.push(newLoginLocation);
|
||||
// only stash if we have a real useragent, otherwise warn the user every time
|
||||
if (!simplifiedUserAgent) loginLocations.push(newLoginLocation);
|
||||
|
||||
userdb.update(user.id, { loginLocations }, function (error) {
|
||||
if (error) console.error('checkLoginLocation: Failed to update user location.', error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user