<commit_before>require 'whiplash'
class ApplicationController < ActionController::Base
  include Bandit
  helper_method :win!, :spin!, :can
  
  protect_from_forgery
  before_filter :add_environment_to_title

  def add_environment_to_title
    @title = "Watchdog.net"
    @title << " - #{Rails.env}" unless Rails.env.production? 
  end
  
  def connecting_ip
    puts "+++++++++request.env+++++++++#{request.env["CF-Connecting-IP"]}+++++++++++++++++++++++++"
    puts "++++all+++++request.env+++++++++#{request.env.inspect}+++++++++++++++++++++++++"
    puts "+++++++remote_ip+++++++++++#{request.remote_ip}++++++++++++++++++++++++"
    request.env["CF-Connecting-IP"] || request.remote_ip
  end
  
  private
  def current_user
    @current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
  end
  helper_method :current_user
    
  def require_login
	  session['redirect_url'] = request.url
    redirect_to login_path if current_user.nil?
  end
    
  def require_admin
    if current_user.nil?
      redirect_to login_path 
    elsif !(current_user.is_admin || current_user.is_super_user)
      render_403
    end
  end

  def render_403
    render :file => "#{Rails.root}/public/403", :formats => [:html], :status => 403
  end
  
  def can(permission)
    current_user && (current_user.is_super_user || current_user.is_admin)
  end
  
  def role
    if can :admin
      :admin
    else
      :default
    end
  end
end
<commit_msg>fixed wrong CF http header name<commit_after>require 'whiplash'
class ApplicationController < ActionController::Base
  include Bandit
  helper_method :win!, :spin!, :can
  
  protect_from_forgery
  before_filter :add_environment_to_title

  def add_environment_to_title
    @title = "Watchdog.net"
    @title << " - #{Rails.env}" unless Rails.env.production? 
  end
  
  def connecting_ip
    request.env["HTTP_CF_CONNECTING_IP"] || request.remote_ip
  end
  
  private
  def current_user
    @current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
  end
  helper_method :current_user
    
  def require_login
	  session['redirect_url'] = request.url
    redirect_to login_path if current_user.nil?
  end
    
  def require_admin
    if current_user.nil?
      redirect_to login_path 
    elsif !(current_user.is_admin || current_user.is_super_user)
      render_403
    end
  end

  def render_403
    render :file => "#{Rails.root}/public/403", :formats => [:html], :status => 403
  end
  
  def can(permission)
    current_user && (current_user.is_super_user || current_user.is_admin)
  end
  
  def role
    if can :admin
      :admin
    else
      :default
    end
  end
end

{'fraction_non_alphanumeric': 0.14080785201963006, 'fraction_numerical': 0.009060022650056626, 'mean_word_length': 3.6167247386759582, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4320018', 'n_tokens_mistral': 922, 'n_tokens_neox': 881, 'n_words': 183}