Files

70 lines
1.7 KiB
Ruby

module Public
class SiteBaseController < ActionController::Base
layout "marketing"
include ::SeoHelper
include ::LegalHelper
helper ApplicationHelper
helper_method :current_user, :logged_in?, :current_locale, :language_options, :current_language_option
protect_from_forgery with: :exception
before_action :set_site_locale
before_action :load_site_announcements
private
def set_site_locale
I18n.locale = LocaleResolver.resolve(
cookie_jar: request.cookie_jar,
accept_language: request.get_header("HTTP_ACCEPT_LANGUAGE")
)
end
def current_locale
I18n.locale
end
def language_options
LocaleResolver.language_options
end
def current_language_option
LocaleResolver.current_language_option
end
def current_user
return @current_user if defined?(@current_user)
@current_user = User.find_by(id: session[:user_id]) if session[:user_id]
end
def logged_in?
current_user.present?
end
PRIVATE_WEB_CONTROLLERS = %w[
accounts clubs teams club_recordings club_billing
club_matches matches team_roster_members
tournaments tournament_participants tournament_groups
tournament_matches tournament_invitations tournament_results
].freeze
def load_site_announcements
@site_announcements = if skip_site_announcements?
AppAnnouncement.none
else
channel = private_web_area? ? :web_private : :web_public
AppAnnouncement.for_channel(channel).newest
end
end
def skip_site_announcements?
controller_name == "regia"
end
def private_web_area?
PRIVATE_WEB_CONTROLLERS.include?(controller_name)
end
end
end