Fallback to unkown useragent and don't stash such login attempts

This commit is contained in:
Johannes Zellner
2021-05-04 20:02:53 +02:00
parent bec42c69c8
commit fed8ba95f0
2 changed files with 5 additions and 3 deletions

View File

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