Added extra notification for new country signin.
This commit is contained in:
parent
cba04e153d
commit
fd58ac0a29
6 changed files with 68 additions and 14 deletions
|
@ -142,7 +142,7 @@ class ApplicationController < ActionController::Base
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# add defice if needed
|
# add device if needed
|
||||||
user_device = UserDevice.add(
|
user_device = UserDevice.add(
|
||||||
request.env['HTTP_USER_AGENT'],
|
request.env['HTTP_USER_AGENT'],
|
||||||
request.remote_ip,
|
request.remote_ip,
|
||||||
|
|
|
@ -7,7 +7,7 @@ class UserDevice < ApplicationModel
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
store device for user
|
store new device for user if device not already known
|
||||||
|
|
||||||
user_device = UserDevice.add(
|
user_device = UserDevice.add(
|
||||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
|
||||||
|
@ -34,13 +34,17 @@ store device for user
|
||||||
end
|
end
|
||||||
|
|
||||||
# find device by fingerprint
|
# find device by fingerprint
|
||||||
|
device_exists_by_fingerprint = false
|
||||||
if fingerprint
|
if fingerprint
|
||||||
user_device = UserDevice.find_by(
|
user_devices = UserDevice.where(
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
fingerprint: fingerprint,
|
fingerprint: fingerprint,
|
||||||
location: location,
|
|
||||||
)
|
)
|
||||||
return action(user_device.id, user_agent, ip, user_id) if user_device
|
user_devices.each {|local_user_device|
|
||||||
|
device_exists_by_fingerprint = true
|
||||||
|
next if local_user_device.location != location
|
||||||
|
return action(local_user_device.id, user_agent, ip, user_id) if local_user_device
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# for basic_auth|token_auth search for user agent
|
# for basic_auth|token_auth search for user agent
|
||||||
|
@ -112,7 +116,13 @@ store device for user
|
||||||
# send notification if needed
|
# send notification if needed
|
||||||
user_devices = UserDevice.where(user_id: user_id).count
|
user_devices = UserDevice.where(user_id: user_id).count
|
||||||
if user_devices >= 2
|
if user_devices >= 2
|
||||||
user_device.send_notification
|
|
||||||
|
# notify on now device of if country has changed
|
||||||
|
if device_exists_by_fingerprint
|
||||||
|
user_device.notification_send('user_device_new_location')
|
||||||
|
else
|
||||||
|
user_device.notification_send('user_device_new')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user_device
|
user_device
|
||||||
|
@ -141,6 +151,11 @@ log user device action
|
||||||
user_device.location_details = location_details
|
user_device.location_details = location_details
|
||||||
|
|
||||||
location = location_details['country_name']
|
location = location_details['country_name']
|
||||||
|
|
||||||
|
# notify if country has changed
|
||||||
|
if user_device.location != location
|
||||||
|
user_device.notification_send('user_device_new_location')
|
||||||
|
end
|
||||||
user_device.location = location
|
user_device.location = location
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -152,19 +167,19 @@ log user device action
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
send new user device info
|
send user notification about new device or new location for device
|
||||||
|
|
||||||
user_device = UserDevice.find(id)
|
user_device = UserDevice.find(id)
|
||||||
|
|
||||||
user_device.send_notification
|
user_device.notification_send('user_device_new_location')
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def send_notification
|
def notification_send(template)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
||||||
NotificationFactory.notification(
|
NotificationFactory.notification(
|
||||||
template: 'user_device',
|
template: template,
|
||||||
user: user,
|
user: user,
|
||||||
objects: {
|
objects: {
|
||||||
user_device: self,
|
user_device: self,
|
||||||
|
@ -172,4 +187,5 @@ send new user device info
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
<p>Hallo <%= d 'user.firstname' %>,</p>
|
<p>Hallo <%= d 'user.firstname' %>,</p>
|
||||||
<br>
|
<br>
|
||||||
<p>es sieht aus, als ob Du Dich bei <%= c 'product_name' %> mit einem neuen Gerät um "<%= d 'user_device.created_at' %>" angemeldet hast:</p>
|
<p>es sieht aus, als ob Du Dich mit <b>einem neuen Gerät</b> um "<%= d 'user_device.created_at' %>" angemeldet hast:</p>
|
||||||
<br>
|
<br>
|
||||||
<p>
|
<p>
|
||||||
Dein Gerät: <%= d 'user_device.name' %><br>
|
Dein Gerät: <%= d 'user_device.name' %><br>
|
||||||
Deine Lokation (relativ): <%= d 'user_device.location' %><br>
|
Deine Lokation (relativ): <%= d 'user_device.location' %><br>
|
||||||
Deine IP: <%= d 'user_device.ip' %><br
|
Deine IP: <%= d 'user_device.ip' %><br>
|
||||||
</p>
|
</p>
|
||||||
<br>
|
<br>
|
||||||
<p>Das Gerät wurde in die Liste der bekannten Geräte hinzugefügt, diese Liste kannst Du hier einsehen:</p>
|
<p>Das Gerät wurde in die Liste der bekannten Geräte hinzugefügt, diese Liste kannst Du hier einsehen:</p>
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
<p>Hi <%= d 'user.firstname' %>,</p>
|
<p>Hi <%= d 'user.firstname' %>,</p>
|
||||||
<br>
|
<br>
|
||||||
<p>It looks like you signed into your <%= c 'product_name' %> account using a new device on "<%= d 'user_device.created_at' %>":</p>
|
<p>It looks like you signed into your account <b>using a new device</b> on "<%= d 'user_device.created_at' %>":</p>
|
||||||
<br>
|
<br>
|
||||||
<p>
|
<p>
|
||||||
Your device: <%= d 'user_device.name' %><br>
|
Your device: <%= d 'user_device.name' %><br>
|
||||||
Your location (relative): <%= d 'user_device.location' %><br>
|
Your location (relative): <%= d 'user_device.location' %><br>
|
||||||
Your IP: <%= d 'user_device.ip' %><br
|
Your IP: <%= d 'user_device.ip' %><br>
|
||||||
</p>
|
</p>
|
||||||
<br>
|
<br>
|
||||||
<p>Your device has been added to your list of known devices, which you can view here:</p>
|
<p>Your device has been added to your list of known devices, which you can view here:</p>
|
19
app/views/mailer/user_device_new_location/de.html.erb
Normal file
19
app/views/mailer/user_device_new_location/de.html.erb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<%= c 'product_name' %>-Anmeldung von einem anderen Land erfasst
|
||||||
|
|
||||||
|
<p>Hallo <%= d 'user.firstname' %>,</p>
|
||||||
|
<br>
|
||||||
|
<p>es sieht aus, als ob Du Dich um "<%= d 'user_device.created_at' %>" von einem <b>bekannten Gerät aus einem anderen Land angemeldet hast</b>:</p>
|
||||||
|
<br>
|
||||||
|
<p>
|
||||||
|
Dein Gerät: <%= d 'user_device.name' %><br>
|
||||||
|
Deine Lokation (relativ): <%= d 'user_device.location' %><br>
|
||||||
|
Deine IP: <%= d 'user_device.ip' %><br
|
||||||
|
</p>
|
||||||
|
<br>
|
||||||
|
<p>Das neue Land wurde in die Liste der bekannten Geräte hinzugefügt, diese Liste kannst Du hier einsehen:</p>
|
||||||
|
<br>
|
||||||
|
<p><%= c 'http_type' %>://<%= c 'fqdn' %>/#profile/devices</p>
|
||||||
|
<br>
|
||||||
|
<p>Wenn dies nicht Du warst, entferne die neue Lokation aus der Liste, ändere Dein Account-Passwort und kontaktieren Deinen Administrator. Jemand könnte unberechtigten Zugriff auf Dein Konto bekommen haben.</p>
|
||||||
|
<br>
|
||||||
|
<p>Dein <%= c 'product_name' %> Team</p>
|
19
app/views/mailer/user_device_new_location/en.html.erb
Normal file
19
app/views/mailer/user_device_new_location/en.html.erb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<%= c 'product_name' %> signin detected from a new country
|
||||||
|
|
||||||
|
<p>Hi <%= d 'user.firstname' %>,</p>
|
||||||
|
<br>
|
||||||
|
<p>It looks like you used your account with an <b>knwon device but from a new country</b> on "<%= d 'user_device.created_at' %>":</p>
|
||||||
|
<br>
|
||||||
|
<p>
|
||||||
|
Your device: <%= d 'user_device.name' %><br>
|
||||||
|
Your location (relative): <%= d 'user_device.location' %><br>
|
||||||
|
Your IP: <%= d 'user_device.ip' %><br
|
||||||
|
</p>
|
||||||
|
<br>
|
||||||
|
<p>The country has been added to your list of known devices, which you can view here:</p>
|
||||||
|
<br>
|
||||||
|
<p><%= c 'http_type' %>://<%= c 'fqdn' %>/#profile/devices</p>
|
||||||
|
<br>
|
||||||
|
<p>If this wasn't you, remove the device, changing your account password, and contacting your administrator. Somebody might have gained unauthorized access to your account.</p>
|
||||||
|
<br>
|
||||||
|
<p>Your <%= c 'product_name' %> Team</p>
|
Loading…
Reference in a new issue