settings_helper.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. module Admin::SettingsHelper
  3. def captcha_available?
  4. ENV['HCAPTCHA_SECRET_KEY'].present? && ENV['HCAPTCHA_SITE_KEY'].present?
  5. end
  6. def login_activity_title(activity)
  7. t(
  8. "login_activities.#{login_activity_key(activity)}",
  9. method: login_activity_method(activity),
  10. ip: login_activity_ip(activity),
  11. browser: login_activity_browser(activity)
  12. )
  13. end
  14. private
  15. def login_activity_key(activity)
  16. activity.success? ? 'successful_sign_in_html' : 'failed_sign_in_html'
  17. end
  18. def login_activity_method(activity)
  19. content_tag(
  20. :span,
  21. login_activity_method_string(activity),
  22. class: 'target'
  23. )
  24. end
  25. def login_activity_ip(activity)
  26. content_tag(
  27. :span,
  28. activity.ip,
  29. class: 'target'
  30. )
  31. end
  32. def login_activity_browser(activity)
  33. content_tag(
  34. :span,
  35. login_activity_browser_description(activity),
  36. class: 'target',
  37. title: activity.user_agent
  38. )
  39. end
  40. def login_activity_method_string(activity)
  41. if activity.omniauth?
  42. t("auth.providers.#{activity.provider}")
  43. else
  44. t("login_activities.authentication_methods.#{activity.authentication_method}")
  45. end
  46. end
  47. def login_activity_browser_description(activity)
  48. t(
  49. 'sessions.description',
  50. browser: t(activity.browser, scope: 'sessions.browsers', default: activity.browser.to_s),
  51. platform: t(activity.platform, scope: 'sessions.platforms', default: activity.platform.to_s)
  52. )
  53. end
  54. end