<commit_before>class RubygemsController < ApplicationController
  skip_before_filter :verify_authenticity_token, :only => :create
  before_filter :authenticate, :only => :create
  before_filter :redirect_to_root, :only => [:migrate, :mine, :edit, :update], :unless => :signed_in?
  before_filter :load_gem, :only => [:edit, :update]

  def mine
    @gems = current_user.rubygems
  end

  def index
    @gems = Rubygem.paginate :page => params[:page], :order => "name asc", :conditions => "name <> ''"
  end

  def show
    @gem = Rubygem.find(params[:id])
    @current_version = @gem.versions.current
    @current_dependencies = @current_version.dependencies if @current_version
  end

  def edit
  end

  def migrate
    @gem = Rubygem.find(params[:id])

    if @gem.unowned?
      @ownership = Ownership.find_or_create_by_user_id_and_rubygem_id(current_user.id, @gem.id)
    else
      flash[:failure] = "This gem has already been migrated."
      redirect_to rubygem_path(@gem)
    end
  end

  def update
    if @linkset.update_attributes(params[:linkset])
      redirect_to rubygem_path(@gem)
      flash[:success] = "Gem links updated."
    else
      render :edit
    end
  end

  def create
    gemcutter = Gemcutter.new(current_user, request.body)
    gemcutter.process
    render :text => gemcutter.message, :status => gemcutter.code
  end

  protected
    def authenticate
      logger.info request.headers.inspect
      @_current_user = User.find_by_api_key(request.headers["HTTP_AUTHORIZATION"])
      if current_user.nil?
        render :text => "Access Denied. Please sign up for an account at http://gemcutter.org", :status => 401
      elsif !current_user.email_confirmed
        render :text => "Access Denied. Please confirm your Gemcutter account.", :status => 403
      end
    end

    def load_gem
      @gem = Rubygem.find(params[:id])

      if !@gem.owned_by?(current_user)
        flash[:warning] = "You do not have permission to edit this gem."
        redirect_to root_url
      end

      @linkset = @gem.linkset
    end
end<commit_msg>Trying the Authorization header instead<commit_after>class RubygemsController < ApplicationController
  skip_before_filter :verify_authenticity_token, :only => :create
  before_filter :authenticate, :only => :create
  before_filter :redirect_to_root, :only => [:migrate, :mine, :edit, :update], :unless => :signed_in?
  before_filter :load_gem, :only => [:edit, :update]

  def mine
    @gems = current_user.rubygems
  end

  def index
    @gems = Rubygem.paginate :page => params[:page], :order => "name asc", :conditions => "name <> ''"
  end

  def show
    @gem = Rubygem.find(params[:id])
    @current_version = @gem.versions.current
    @current_dependencies = @current_version.dependencies if @current_version
  end

  def edit
  end

  def migrate
    @gem = Rubygem.find(params[:id])

    if @gem.unowned?
      @ownership = Ownership.find_or_create_by_user_id_and_rubygem_id(current_user.id, @gem.id)
    else
      flash[:failure] = "This gem has already been migrated."
      redirect_to rubygem_path(@gem)
    end
  end

  def update
    if @linkset.update_attributes(params[:linkset])
      redirect_to rubygem_path(@gem)
      flash[:success] = "Gem links updated."
    else
      render :edit
    end
  end

  def create
    gemcutter = Gemcutter.new(current_user, request.body)
    gemcutter.process
    render :text => gemcutter.message, :status => gemcutter.code
  end

  protected
    def authenticate
      logger.info request.headers.inspect
      @_current_user = User.find_by_api_key(request.headers["Authorization"])
      if current_user.nil?
        render :text => "Access Denied. Please sign up for an account at http://gemcutter.org", :status => 401
      elsif !current_user.email_confirmed
        render :text => "Access Denied. Please confirm your Gemcutter account.", :status => 403
      end
    end

    def load_gem
      @gem = Rubygem.find(params[:id])

      if !@gem.owned_by?(current_user)
        flash[:warning] = "You do not have permission to edit this gem."
        redirect_to root_url
      end

      @linkset = @gem.linkset
    end
end
{'fraction_non_alphanumeric': 0.10739224656874549, 'fraction_numerical': 0.002889477486154587, 'mean_word_length': 3.3136033229491173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '5510618', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1314, 'n_words': 333}