2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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-12-20 04:23:05 -05:00
|
|
|
ipinfo[:location].presence || I18n.t('staff_action_logs.unknown')
|
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
|
2019-02-28 13:03:14 -05:00
|
|
|
'fab-android'
|
2019-05-30 09:29:43 -04:00
|
|
|
when :chromeos
|
|
|
|
'fab-chrome'
|
2018-10-09 10:21:41 -04:00
|
|
|
when :macos, :ios
|
2019-02-28 13:03:14 -05:00
|
|
|
'fab-apple'
|
2018-10-09 10:21:41 -04:00
|
|
|
when :linux
|
2019-02-28 13:03:14 -05:00
|
|
|
'fab-linux'
|
2018-10-09 10:21:41 -04:00
|
|
|
when :windows
|
2019-02-28 13:03:14 -05:00
|
|
|
'fab-windows'
|
2018-09-02 22:44:22 -04:00
|
|
|
else
|
|
|
|
'question'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|