diff --git a/src/mail_templates/new_login_location-html.ejs b/src/mail_templates/new_login_location-html.ejs index 301f4d906..ff4a2147c 100644 --- a/src/mail_templates/new_login_location-html.ejs +++ b/src/mail_templates/new_login_location-html.ejs @@ -2,14 +2,15 @@ -

We've noticed a new login on your Cloudron <%= cloudronName %>

+

We've noticed a new login on your Cloudron account.

Hi <%= user %>,

We noticed a login on your Cloudron account from a new device.

-

Browser <%= userAgent %> - <%= city %>, <%= country %>

+

IP: <%= ip %> (<%= city %>, <%= country %>)

+

Browser: <%= userAgent %>

-

If this was you, you can safely disregard this email. If this wasn't you, you should change your password immediately

+

If this was you, you can safely disregard this email. If this wasn't you, you should change your password immediately.



diff --git a/src/mail_templates/new_login_location-text.ejs b/src/mail_templates/new_login_location-text.ejs index b9b0578cf..34f3746c9 100644 --- a/src/mail_templates/new_login_location-text.ejs +++ b/src/mail_templates/new_login_location-text.ejs @@ -1,11 +1,14 @@ -We've noticed a new login on your Cloudron <%= cloudronName %> +We've noticed a new login on your Cloudron account. Hi <%= user %>, We noticed a login on your Cloudron account from a new device. -Browser <%= userAgent %> - <%= city %>, <%= country %> -If this was you, you can safely disregard this email. If this wasn't you, you should change your password immediately +IP: <%= ip %> (<%= city %>, <%= country %>) + +Browser: <%= userAgent %> + +If this was you, you can safely disregard this email. If this wasn't you, you should change your password immediately. Powered by https://cloudron.io diff --git a/src/mailer.js b/src/mailer.js index c1e460052..9bb02580f 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -142,8 +142,12 @@ function sendInvite(user, invitor, inviteLink) { }); } -function sendNewLoginLocation(user, ip, userAgent, country, city) { +function sendNewLoginLocation(user, loginLocation) { assert.strictEqual(typeof user, 'object'); + assert.strictEqual(typeof loginLocation, 'object'); + + const { ip, userAgent, country, city } = loginLocation; + assert.strictEqual(typeof ip, 'string'); assert.strictEqual(typeof userAgent, 'string'); assert.strictEqual(typeof country, 'string'); @@ -157,20 +161,20 @@ function sendNewLoginLocation(user, ip, userAgent, country, city) { translation.getTranslations(function (error, translationAssets) { if (error) return debug('Error getting translations:', error); - var templateData = { + const templateData = { user: user.displayName || user.username || user.email, - ip: ip, - userAgent: userAgent, - country: country, - city: city, + ip, + userAgent, + country, + city, cloudronName: mailConfig.cloudronName, cloudronAvatarUrl: settings.adminOrigin() + '/api/v1/cloudron/avatar' }; - var mailOptions = { + const mailOptions = { from: mailConfig.notificationFrom, to: user.fallbackEmail, - subject: `[${mailConfig.cloudronName}] Login from new location detected`, + subject: `[${mailConfig.cloudronName}] New login on your account`, text: render('new_login_location-text.ejs', templateData, translationAssets), html: render('new_login_location-html.ejs', templateData, translationAssets) }; diff --git a/src/users.js b/src/users.js index 51a1cf144..fe87c28ff 100644 --- a/src/users.js +++ b/src/users.js @@ -553,13 +553,14 @@ function checkLoginLocation(user, ip, userAgent) { // purge potentially old locations where ts > now() - 6 months const sixMonthsBack = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000; + const newLoginLocation = { ts: Date.now(), ip, userAgent, country, city }; let loginLocations = user.loginLocations.filter(function (l) { return l.ts > sixMonthsBack; }); - loginLocations.push({ ts: Date.now(), ip, userAgent, country, city }); + loginLocations.push(newLoginLocation); 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); + mailer.sendNewLoginLocation(user, newLoginLocation); }); }); }