<commit_before># Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception, only: [:edit, :update, :delete]

  before_action :fire_triggers, :load_lang, :set_paths
  before_action :configure_permitted_parameters, if: :devise_controller?

  private

  def configure_permitted_parameters
    # TODO: Check if this is still needed
    devise_parameter_sanitizer.permit(:sign_up, keys: [:email])
  end

  def login_required
    authenticate_user! && authorize!(params[:action], params[:controller])
  end

  def set_paths
    prepend_view_path "#{::Rails.root}/themes/#{this_blog.theme}/views"
    Dir.glob(File.join(::Rails.root.to_s, 'lib', '*_sidebar/app/views')).select do |file|
      append_view_path file
    end
  end

  def fire_triggers
    Trigger.fire
  end

  def load_lang
    if I18n.available_locales.include?(this_blog.lang.to_sym)
      I18n.locale = this_blog.lang
    elsif I18n.available_locales.include?(this_blog.lang[0..1].to_sym)
      I18n.locale = this_blog.lang[0..1]
    # for the same language used in different areas, e.g. zh_CN, zh_TW
    elsif I18n.available_locales.include?(this_blog.lang.sub('_', '-').to_sym)
      I18n.locale = this_blog.lang.sub('_', '-')
    end
  end

  def add_to_cookies(name, value, path = nil, _expires = nil)
    cookies[name] = { value: value, path: path || "/#{controller_name}", expires: 6.weeks.from_now }
  end

  include BlogHelper
end
<commit_msg>Protect from forgery on all actions<commit_after># Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  before_action :fire_triggers, :load_lang, :set_paths
  before_action :configure_permitted_parameters, if: :devise_controller?

  private

  def configure_permitted_parameters
    # TODO: Check if this is still needed
    devise_parameter_sanitizer.permit(:sign_up, keys: [:email])
  end

  def login_required
    authenticate_user! && authorize!(params[:action], params[:controller])
  end

  def set_paths
    prepend_view_path "#{::Rails.root}/themes/#{this_blog.theme}/views"
    Dir.glob(File.join(::Rails.root.to_s, 'lib', '*_sidebar/app/views')).select do |file|
      append_view_path file
    end
  end

  def fire_triggers
    Trigger.fire
  end

  def load_lang
    if I18n.available_locales.include?(this_blog.lang.to_sym)
      I18n.locale = this_blog.lang
    elsif I18n.available_locales.include?(this_blog.lang[0..1].to_sym)
      I18n.locale = this_blog.lang[0..1]
    # for the same language used in different areas, e.g. zh_CN, zh_TW
    elsif I18n.available_locales.include?(this_blog.lang.sub('_', '-').to_sym)
      I18n.locale = this_blog.lang.sub('_', '-')
    end
  end

  def add_to_cookies(name, value, path = nil, _expires = nil)
    cookies[name] = { value: value, path: path || "/#{controller_name}", expires: 6.weeks.from_now }
  end

  include BlogHelper
end

{'fraction_non_alphanumeric': 0.11132016306052053, 'fraction_numerical': 0.01066164941988084, 'mean_word_length': 4.1618122977346275, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3618085', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1062, 'n_words': 253}