donphan/app/helpers/admin/settings_helper.rb

64 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Admin::SettingsHelper
2023-05-16 22:27:35 +01:00
def captcha_available?
ENV['HCAPTCHA_SECRET_KEY'].present? && ENV['HCAPTCHA_SITE_KEY'].present?
end
def login_activity_title(activity)
t(
"login_activities.#{login_activity_key(activity)}",
method: login_activity_method(activity),
ip: login_activity_ip(activity),
browser: login_activity_browser(activity)
)
end
private
def login_activity_key(activity)
activity.success? ? 'successful_sign_in_html' : 'failed_sign_in_html'
end
def login_activity_method(activity)
content_tag(
:span,
login_activity_method_string(activity),
class: 'target'
)
end
def login_activity_ip(activity)
content_tag(
:span,
activity.ip,
class: 'target'
)
end
def login_activity_browser(activity)
content_tag(
:span,
login_activity_browser_description(activity),
class: 'target',
title: activity.user_agent
)
end
def login_activity_method_string(activity)
if activity.omniauth?
t("auth.providers.#{activity.provider}")
else
t("login_activities.authentication_methods.#{activity.authentication_method}")
end
end
def login_activity_browser_description(activity)
t(
'sessions.description',
browser: t(activity.browser, scope: 'sessions.browsers', default: activity.browser.to_s),
platform: t(activity.platform, scope: 'sessions.platforms', default: activity.platform.to_s)
)
end
end