Improved device detection for user agent and different countries.
This commit is contained in:
parent
2a295e78ab
commit
2a2538a7a9
1 changed files with 13 additions and 8 deletions
|
@ -43,18 +43,22 @@ store new device for user if device not already known
|
|||
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
|
||||
return action(local_user_device.id, user_agent, ip, user_id, type) if local_user_device
|
||||
}
|
||||
end
|
||||
|
||||
# for basic_auth|token_auth search for user agent
|
||||
device_exists_by_user_agent = false
|
||||
if type == 'basic_auth' || type == 'token_auth'
|
||||
user_device = UserDevice.find_by(
|
||||
user_devices = UserDevice.where(
|
||||
user_id: user_id,
|
||||
user_agent: user_agent,
|
||||
location: location,
|
||||
)
|
||||
return action(user_device.id, user_agent, ip, user_id) if user_device
|
||||
user_devices.each {|local_user_device|
|
||||
device_exists_by_user_agent = true
|
||||
next if local_user_device.location != location
|
||||
return action(local_user_device.id, user_agent, ip, user_id, type) if local_user_device
|
||||
}
|
||||
end
|
||||
|
||||
# get browser details
|
||||
|
@ -97,7 +101,7 @@ store new device for user if device not already known
|
|||
)
|
||||
|
||||
if user_device
|
||||
return action(user_device.id, user_agent, ip, user_id) if user_device
|
||||
return action(user_device.id, user_agent, ip, user_id, type) if user_device
|
||||
end
|
||||
|
||||
# create new device
|
||||
|
@ -119,7 +123,7 @@ store new device for user if device not already known
|
|||
if user_devices >= 2
|
||||
|
||||
# notify on now device of if country has changed
|
||||
if device_exists_by_fingerprint
|
||||
if device_exists_by_fingerprint || device_exists_by_user_agent
|
||||
user_device.notification_send('user_device_new_location')
|
||||
else
|
||||
user_device.notification_send('user_device_new')
|
||||
|
@ -138,11 +142,12 @@ log user device action
|
|||
'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',
|
||||
'172.0.0.1',
|
||||
user.id,
|
||||
'session', # session|basic_auth|token_auth|sso
|
||||
)
|
||||
|
||||
=end
|
||||
|
||||
def self.action(user_device_id, user_agent, ip, user_id)
|
||||
def self.action(user_device_id, user_agent, ip, user_id, type)
|
||||
user_device = UserDevice.find(user_device_id)
|
||||
|
||||
# update location if needed
|
||||
|
@ -160,7 +165,7 @@ log user device action
|
|||
ip,
|
||||
user_id,
|
||||
user_device.fingerprint,
|
||||
'session',
|
||||
type,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue