Fixed issue #1208 - Too many emails about new client access if user agent is "".
This commit is contained in:
parent
3e92e4f9f4
commit
6a4e17a224
2 changed files with 53 additions and 13 deletions
|
@ -21,8 +21,9 @@ store new device for user if device not already known
|
||||||
|
|
||||||
def self.add(user_agent, ip, user_id, fingerprint, type)
|
def self.add(user_agent, ip, user_id, fingerprint, type)
|
||||||
|
|
||||||
# since gem browser 2 is not handling nil for user_agent, set it to ''
|
if user_agent.blank?
|
||||||
user_agent ||= ''
|
user_agent = 'unknown'
|
||||||
|
end
|
||||||
|
|
||||||
# get location info
|
# get location info
|
||||||
location_details = Service::GeoIp.location(ip)
|
location_details = Service::GeoIp.location(ip)
|
||||||
|
@ -60,23 +61,26 @@ store new device for user if device not already known
|
||||||
end
|
end
|
||||||
|
|
||||||
# get browser details
|
# get browser details
|
||||||
browser = Browser.new(user_agent, accept_language: 'en-us')
|
browser = {}
|
||||||
browser = {
|
if user_agent != 'unknown'
|
||||||
plattform: browser.platform.to_s.camelize,
|
browser = Browser.new(user_agent, accept_language: 'en-us')
|
||||||
name: browser.name,
|
browser = {
|
||||||
version: browser.version,
|
plattform: browser.platform.to_s.camelize,
|
||||||
full_version: browser.full_version,
|
name: browser.name,
|
||||||
}
|
version: browser.version,
|
||||||
|
full_version: browser.full_version,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# generate device name
|
# generate device name
|
||||||
if browser[:name] == 'Generic Browser'
|
if browser[:name] == 'Generic Browser'
|
||||||
browser[:name] = user_agent
|
browser[:name] = user_agent
|
||||||
end
|
end
|
||||||
name = ''
|
name = ''
|
||||||
if browser[:plattform] && browser[:plattform] != 'Other'
|
if browser[:plattform].present? && browser[:plattform] != 'Other'
|
||||||
name = browser[:plattform]
|
name = browser[:plattform]
|
||||||
end
|
end
|
||||||
if browser[:name] && browser[:name] != 'Other'
|
if browser[:name].present? && browser[:name] != 'Other'
|
||||||
if name.present?
|
if name.present?
|
||||||
name += ', '
|
name += ', '
|
||||||
end
|
end
|
||||||
|
@ -84,7 +88,7 @@ store new device for user if device not already known
|
||||||
end
|
end
|
||||||
|
|
||||||
# if not identified, use user agent
|
# if not identified, use user agent
|
||||||
if !name || name == '' || name == 'Other, Other' || name == 'Other'
|
if name.blank? || name == 'Other, Other' || name == 'Other'
|
||||||
name = user_agent
|
name = user_agent
|
||||||
browser[:name] = user_agent
|
browser[:name] = user_agent
|
||||||
end
|
end
|
||||||
|
@ -103,7 +107,7 @@ store new device for user if device not already known
|
||||||
end
|
end
|
||||||
|
|
||||||
# create new device
|
# create new device
|
||||||
user_device = create(
|
user_device = create!(
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
name: name,
|
name: name,
|
||||||
os: browser[:plattform],
|
os: browser[:plattform],
|
||||||
|
|
|
@ -204,6 +204,42 @@ class UserDeviceTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
assert_equal(user_device2.id, user_device6.id)
|
assert_equal(user_device2.id, user_device6.id)
|
||||||
|
|
||||||
|
# signin without ua from country A via basic auth -> new device #3
|
||||||
|
user_device7 = UserDevice.add(
|
||||||
|
'',
|
||||||
|
'91.115.248.231',
|
||||||
|
@agent.id,
|
||||||
|
nil,
|
||||||
|
'basic_auth',
|
||||||
|
)
|
||||||
|
assert_not_equal(user_device6.id, user_device7.id)
|
||||||
|
|
||||||
|
user_device8 = UserDevice.add(
|
||||||
|
'',
|
||||||
|
'91.115.248.231',
|
||||||
|
@agent.id,
|
||||||
|
nil,
|
||||||
|
'basic_auth',
|
||||||
|
)
|
||||||
|
assert_equal(user_device7.id, user_device8.id)
|
||||||
|
|
||||||
|
user_device9 = UserDevice.add(
|
||||||
|
nil,
|
||||||
|
'91.115.248.231',
|
||||||
|
@agent.id,
|
||||||
|
nil,
|
||||||
|
'basic_auth',
|
||||||
|
)
|
||||||
|
assert_equal(user_device8.id, user_device9.id)
|
||||||
|
|
||||||
|
user_device10 = UserDevice.add(
|
||||||
|
nil,
|
||||||
|
'176.198.137.254',
|
||||||
|
@agent.id,
|
||||||
|
nil,
|
||||||
|
'basic_auth',
|
||||||
|
)
|
||||||
|
assert_not_equal(user_device9.id, user_device10.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'ddd - api test' do
|
test 'ddd - api test' do
|
||||||
|
|
Loading…
Reference in a new issue