<commit_before>class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :set_current_user
  
  def set_current_user
    #try to get the user from the rails session
    return @current_user if @current_user
    
    #if that fails, try to get the user_id from a cookie
    user_id = cookies[:current_user_id]
    
    #try to find the user
    if user_id
      begin
        @current_user = User.find(user_id)
        return @current_user
      rescue Exception => e
        #user not found shouldn't mask other possible errors
        raise e unless e.is_a? ActiveRecord::RecordNotFound
      end
    end
    
    #if the user_id wasn't cookied or the cookied user_id wasn't found, 
    #we'll end up here, so create a new "guest" user and cookie its id
    @current_user = User.create
    cookies[:current_user_id] = { value: @current_user.id, :expires => Time.now + 365 * 24 * 60 * 60 }
    @current_user
  end
  
  def require_admin
    redirect_to '/' unless @current_user.admin?
  end
end<commit_msg>temporarily disables require_admin<commit_after>class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :set_current_user
  
  def set_current_user
    #try to get the user from the rails session
    return @current_user if @current_user
    
    #if that fails, try to get the user_id from a cookie
    user_id = cookies[:current_user_id]
    
    #try to find the user
    if user_id
      begin
        @current_user = User.find(user_id)
        return @current_user
      rescue Exception => e
        #user not found shouldn't mask other possible errors
        raise e unless e.is_a? ActiveRecord::RecordNotFound
      end
    end
    
    #if the user_id wasn't cookied or the cookied user_id wasn't found, 
    #we'll end up here, so create a new "guest" user and cookie its id
    @current_user = User.create
    cookies[:current_user_id] = { value: @current_user.id, :expires => Time.now + 365 * 24 * 60 * 60 }
    @current_user
  end
  
  def require_admin
    #TODO put this back in once admin authentication is set up
    #redirect_to '/' unless @current_user.admin?
  end
end
{'fraction_non_alphanumeric': 0.06382096974720265, 'fraction_numerical': 0.0074595938665561546, 'mean_word_length': 3.0233333333333334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2388492', 'n_tokens_mistral': 754, 'n_tokens_neox': 723, 'n_words': 266}