2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-09 22:21:41 +08:00
|
|
|
require_dependency 'browser_detection'
|
|
|
|
require_dependency 'discourse_ip_info'
|
|
|
|
|
2018-09-03 10:44:22 +08:00
|
|
|
module UserAuthTokensMixin
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
attributes :id,
|
|
|
|
:client_ip,
|
2018-10-09 22:21:41 +08:00
|
|
|
:location,
|
|
|
|
:browser,
|
|
|
|
:device,
|
2018-09-03 10:44:22 +08:00
|
|
|
:os,
|
|
|
|
:icon,
|
|
|
|
:created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def client_ip
|
|
|
|
object.client_ip.to_s
|
|
|
|
end
|
|
|
|
|
2018-10-09 22:21:41 +08:00
|
|
|
def location
|
2018-10-31 09:38:57 +08:00
|
|
|
ipinfo = DiscourseIpInfo.get(client_ip, locale: I18n.locale)
|
2018-12-20 17:23:05 +08:00
|
|
|
ipinfo[:location].presence || I18n.t('staff_action_logs.unknown')
|
2018-09-03 10:44:22 +08:00
|
|
|
end
|
|
|
|
|
2018-10-09 22:21:41 +08:00
|
|
|
def browser
|
|
|
|
val = BrowserDetection.browser(object.user_agent)
|
|
|
|
I18n.t("user_auth_tokens.browser.#{val}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def device
|
|
|
|
val = BrowserDetection.device(object.user_agent)
|
|
|
|
I18n.t("user_auth_tokens.device.#{val}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def os
|
|
|
|
val = BrowserDetection.os(object.user_agent)
|
|
|
|
I18n.t("user_auth_tokens.os.#{val}")
|
2018-09-03 10:44:22 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
2018-10-09 22:21:41 +08:00
|
|
|
case BrowserDetection.os(object.user_agent)
|
|
|
|
when :android
|
2019-03-01 02:03:14 +08:00
|
|
|
'fab-android'
|
2019-05-30 21:29:43 +08:00
|
|
|
when :chromeos
|
|
|
|
'fab-chrome'
|
2018-10-09 22:21:41 +08:00
|
|
|
when :macos, :ios
|
2019-03-01 02:03:14 +08:00
|
|
|
'fab-apple'
|
2018-10-09 22:21:41 +08:00
|
|
|
when :linux
|
2019-03-01 02:03:14 +08:00
|
|
|
'fab-linux'
|
2018-10-09 22:21:41 +08:00
|
|
|
when :windows
|
2019-03-01 02:03:14 +08:00
|
|
|
'fab-windows'
|
2018-09-03 10:44:22 +08:00
|
|
|
else
|
|
|
|
'question'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|