<commit_before>require "application_responder"

class ApplicationController < ActionController::Base
  include GlobalizeFallbacks
  include HasFilters
  include HasOrders
  include AccessDeniedHandler

  default_form_builder ConsulFormBuilder
  protect_from_forgery with: :exception

  before_action :authenticate_http_basic, if: :http_basic_auth_site?

  before_action :ensure_signup_complete
  before_action :set_locale
  before_action :track_email_campaign
  before_action :set_return_url

  check_authorization unless: :devise_controller?
  self.responder = ApplicationResponder

  layout :set_layout
  respond_to :html
  helper_method :current_budget

  private

    def authenticate_http_basic
      authenticate_or_request_with_http_basic do |username, password|
        username == Rails.application.secrets.http_basic_username && password == <PASSWORD>.http_basic_password
      end
    end

    def http_basic_auth_site?
      Rails.application.secrets.http_basic_auth
    end

    def verify_lock
      if current_user.locked?
        redirect_to account_path, alert: t("verification.alert.lock")
      end
    end

    def set_locale
      if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
        session[:locale] = params[:locale]
      end

      if session[:locale] && I18n.available_locales.include?(session[:locale].to_sym)
        locale = session[:locale]
      else
        locale = I18n.default_locale
      end

      if current_user && current_user.locale != locale.to_s
        current_user.update(locale: locale)
      end

      I18n.locale = locale
    end

    def set_layout
      if devise_controller?
        "devise"
      else
        "application"<commit_msg>Refactor set_locale<commit_after>require "application_responder"

class ApplicationController < ActionController::Base
  include GlobalizeFallbacks
  include HasFilters
  include HasOrders
  include AccessDeniedHandler

  default_form_builder ConsulFormBuilder
  protect_from_forgery with: :exception

  before_action :authenticate_http_basic, if: :http_basic_auth_site?

  before_action :ensure_signup_complete
  before_action :set_locale
  before_action :track_email_campaign
  before_action :set_return_url

  check_authorization unless: :devise_controller?
  self.responder = ApplicationResponder

  layout :set_layout
  respond_to :html
  helper_method :current_budget

  private

    def authenticate_http_basic
      authenticate_or_request_with_http_basic do |username, password|
        username == Rails.application.secrets.http_basic_username && password == Rails.application.secrets.http_basic_password
      end
    end

    def http_basic_auth_site?
      Rails.application.secrets.http_basic_auth
    end

    def verify_lock
      if current_user.locked?
        redirect_to account_path, alert: t("verification.alert.lock")
      end
    end

    def set_locale
      I18n.locale = current_locale

      if current_user && current_user.locale != I18n.locale.to_s
        current_user.update(locale: I18n.locale)
      end

      session[:locale] = I18n.locale
    end

    def current_locale
      if I18n.available_locales.include?(params[:locale]&.to_sym)
        params[:locale]
      elsif I18n.available_locales.include?(session[:locale]&.to_sym)
        session[:locale]
      else
        I18n.default_locale
      end
    end

    def set_layout
      if devise_controller?
        "devise"
      else
        "application"
{'fraction_non_alphanumeric': 0.06368876080691642, 'fraction_numerical': 0.006340057636887608, 'mean_word_length': 3.567105263157895, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3857350', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1017, 'n_words': 203}