<commit_before>require "application_responder"

class ApplicationController < ActionController::Base
  include SimpleCaptcha::ControllerHelpers
  include HasFilters
  include HasOrders

  before_action :authenticate_http_basic, if: :http_basic_auth_site?

  before_action :ensure_signup_complete
  before_action :set_locale
  before_action :track_email_campaign

  check_authorization unless: :devise_controller?
  self.responder = ApplicationResponder

  protect_from_forgery with: :exception

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to main_app.root_url, alert: exception.message
  end

  layout :set_layout
  respond_to :html

  private

    def authenticate_http_basic
      authenticate_or_request_with_http_basic do |username, password|<commit_msg>makes cancan return a json error when asked for json and permissions fail<commit_after>require "application_responder"

class ApplicationController < ActionController::Base
  include SimpleCaptcha::ControllerHelpers
  include HasFilters
  include HasOrders

  before_action :authenticate_http_basic, if: :http_basic_auth_site?

  before_action :ensure_signup_complete
  before_action :set_locale
  before_action :track_email_campaign

  check_authorization unless: :devise_controller?
  self.responder = ApplicationResponder

  protect_from_forgery with: :exception

  rescue_from CanCan::AccessDenied do |exception|
    respond_to do |format|
      format.html { redirect_to main_app.root_url, alert: exception.message }
      format.json { render json: {error: exception.message}, status: :forbidden }
    end
  end

  layout :set_layout
  respond_to :html

  private

    def authenticate_http_basic
      authenticate_or_request_with_http_basic do |username, password|
{'fraction_non_alphanumeric': 0.052601486563750716, 'fraction_numerical': 0.0, 'mean_word_length': 5.730769230769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '399830', 'n_tokens_mistral': 518, 'n_tokens_neox': 496, 'n_words': 121}