2018-10-09 10:21:41 -04:00
|
|
|
require_dependency 'browser_detection'
|
|
|
|
require_dependency 'discourse_ip_info'
|
|
|
|
|
2018-09-02 22:44:22 -04:00
|
|
|
module UserAuthTokensMixin
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
attributes :id,
|
|
|
|
:client_ip,
|
2018-10-09 10:21:41 -04:00
|
|
|
:location,
|
|
|
|
:browser,
|
|
|
|
:device,
|
2018-09-02 22:44:22 -04:00
|
|
|
:os,
|
|
|
|
:icon,
|
|
|
|
:created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def client_ip
|
|
|
|
object.client_ip.to_s
|
|
|
|
end
|
|
|
|
|
2018-10-09 10:21:41 -04:00
|
|
|
def location
|
2018-10-30 21:38:57 -04:00
|
|
|
ipinfo = DiscourseIpInfo.get(client_ip, locale: I18n.locale)
|
2018-10-09 10:21:41 -04:00
|
|
|
|
|
|
|
location = [ipinfo[:city], ipinfo[:region], ipinfo[:country]].reject { |x| x.blank? }.join(", ")
|
|
|
|
return I18n.t('staff_action_logs.unknown') if location.blank?
|
|
|
|
|
|
|
|
location
|
2018-09-02 22:44:22 -04:00
|
|
|
end
|
|
|
|
|
2018-10-09 10:21:41 -04: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-02 22:44:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
2018-10-09 10:21:41 -04:00
|
|
|
case BrowserDetection.os(object.user_agent)
|
|
|
|
when :android
|
2018-09-02 22:44:22 -04:00
|
|
|
'android'
|
2018-10-09 10:21:41 -04:00
|
|
|
when :macos, :ios
|
2018-09-02 22:44:22 -04:00
|
|
|
'apple'
|
2018-10-09 10:21:41 -04:00
|
|
|
when :linux
|
2018-09-02 22:44:22 -04:00
|
|
|
'linux'
|
2018-10-09 10:21:41 -04:00
|
|
|
when :windows
|
2018-09-02 22:44:22 -04:00
|
|
|
'windows'
|
|
|
|
else
|
|
|
|
'question'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|