<commit_before># encoding: utf-8
require 'digest/md5'

class ApplicationController < ActionController::Base
  before_filter :set_locale
  before_filter :sanitize_params

  # This is a proxy class to make various nil checks unnecessary
  class AnonymousUser
    def id
      0
    end

    def level
      0
    end

    def name
      "Anonymous"
    end

    def pretty_name
      "Anonymous"
    end

    def is_anonymous?
      true
    end

    def has_permission?(obj, foreign_key = :user_id)
      false
    end

    def can_change?(record, attribute)
      method = "can_change_#{attribute.to_s}?"
      if record.respond_to?(method)
        record.__send__(method, self)
      elsif record.respond_to?(:can_change?)
        record.can_change?(self, attribute)
      else
        false
      end
    end

    def show_samples?
      true
    end

    def has_avatar?
      false
    end

    def language; ""; end
    def secondary_languages; ""; end
    def secondary_language_array; []; end
    def pool_browse_mode; 1; end
    def always_resize_images; true; end

    CONFIG["user_levels"].each do |name, value|
      normalized_name = name.downcase.gsub(/ /, "_")

      define_method("is_#{normalized_name}?") do
        false
      end

      define_method("is_#{normalized_name}_or_higher?") do
        false
      end

      define_method("is_#{normalized_name}_or_lower?") do
        true
      end
    end
  end

  module LoginSystem
    protected
    def access_denied
      previous_url = params[:url] || request.fullpath

      respond_to do |fmt|
        fmt.html {flash[:notice] = "Access denied"; redirect_to(:controller => "user", :action => "login", :url => previous_url)}
        fmt.xml {render :xml => {:success => false, :reason => "access denied"}.to_xml(:root => "response"), :status => 403}
        fmt.json {render :json => {:success => false, :reason => "access denied"}.to_json, :status => 403}
      end
    end

    def set_current_user
      if Rails.env == "test" && session[:user_id]
        @current_user = User.find_by_id(session[:user_id])
      end

      if @current_user == nil && session[:user_id]
        @current_user = User.find_by_id(session[:user_id])
      end

      if @current_user == nil && cookies[:login] && cookies[:pass_hash]
        @current_user = User.authenticate_hash(cookies[:login], cookies[:pass_hash])
      end

      if @current_user == nil && params[:login] && params[:password_hash]
        @current_user = User.authenticate_hash(params[:login], params[:password_hash])
      end
<commit_msg>A bit more modern syntax for set_current_user.<commit_after># encoding: utf-8
require 'digest/md5'

class ApplicationController < ActionController::Base
  before_filter :set_locale
  before_filter :sanitize_params

  # This is a proxy class to make various nil checks unnecessary
  class AnonymousUser
    def id
      0
    end

    def level
      0
    end

    def name
      "Anonymous"
    end

    def pretty_name
      "Anonymous"
    end

    def is_anonymous?
      true
    end

    def has_permission?(obj, foreign_key = :user_id)
      false
    end

    def can_change?(record, attribute)
      method = "can_change_#{attribute.to_s}?"
      if record.respond_to?(method)
        record.__send__(method, self)
      elsif record.respond_to?(:can_change?)
        record.can_change?(self, attribute)
      else
        false
      end
    end

    def show_samples?
      true
    end

    def has_avatar?
      false
    end

    def language; ""; end
    def secondary_languages; ""; end
    def secondary_language_array; []; end
    def pool_browse_mode; 1; end
    def always_resize_images; true; end

    CONFIG["user_levels"].each do |name, value|
      normalized_name = name.downcase.gsub(/ /, "_")

      define_method("is_#{normalized_name}?") do
        false
      end

      define_method("is_#{normalized_name}_or_higher?") do
        false
      end

      define_method("is_#{normalized_name}_or_lower?") do
        true
      end
    end
  end

  module LoginSystem
    protected
    def access_denied
      previous_url = params[:url] || request.fullpath

      respond_to do |fmt|
        fmt.html {flash[:notice] = "Access denied"; redirect_to(:controller => "user", :action => "login", :url => previous_url)}
        fmt.xml {render :xml => {:success => false, :reason => "access denied"}.to_xml(:root => "response"), :status => 403}
        fmt.json {render :json => {:success => false, :reason => "access denied"}.to_json, :status => 403}
      end
    end

    def set_current_user
      if Rails.env.test? and session[:user_id]
        @current_user = User.find(session[:user_id])
      end

      if @current_user == nil && session[:user_id]
        @current_user = User.find_by_id(session[:user_id])
      end

      if @current_user == nil && cookies[:login] && cookies[:pass_hash]
        @current_user = User.authenticate_hash(cookies[:login], cookies[:pass_hash])
      end

      if @current_user == nil && params[:login] && params[:password_hash]
        @current_user = User.authenticate_hash(params[:login], params[:password_hash])
      end

{'fraction_non_alphanumeric': 0.11113266097750193, 'fraction_numerical': 0.004266873545384018, 'mean_word_length': 2.7074047447879224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4879661', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1569, 'n_words': 388}