<commit_before># coding: UTF-8

require 'oauth/controllers/provider_controller'

class OauthController < ApplicationController
  ssl_required :authorize, :request_token, :access_token, :token, :test_request

  include OAuth::Controllers::ProviderController

  skip_before_filter :login_required, :only => :authorize

  def authorize
    if params[:oauth_token]
      unless @token = ::RequestToken.find_by_token(params[:oauth_token])
        render :action => "authorize_failure" and return
      end
      unless @token.invalidated?
        if logged_in?
          @token.authorize!(current_user)
        else
          @token.authorize!(@token.client_application.user)
        end
        @redirect_url = URI.parse(@token.oob? ? @token.client_application.callback_url || "http://cartodb.com" : @token.callback_url)

        unless @redirect_url.to_s.blank?
          @redirect_url.query = @redirect_url.query.blank? ?
                                "oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}" :
                                @redirect_url.query + "&oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}"
          redirect_to @redirect_url.to_s
        else
          render :action => "authorize_success"
        end
      else
        @token.invalidate!
        render :action => "authorize_failure"
      end
    elsif ["code","token"].include?(params[:response_type]) # pick flow
      send "oauth2_authorize_#{params[:response_type]}"
    end
  end

end<commit_msg>Small refactor in authorize method<commit_after># coding: UTF-8

require 'oauth/controllers/provider_controller'

class OauthController < ApplicationController
  ssl_required :authorize, :request_token, :access_token, :token, :test_request

  include OAuth::Controllers::ProviderController

  skip_before_filter :login_required, :only => :authorize

  def authorize
    unless params[:oauth_token]
      render :nothing => true, :status => 404 and return
    end
    unless @token = ::RequestToken.find_by_token(params[:oauth_token])
      render :action => "authorize_failure" and return
    end
    if @token.invalidated?
      render :action => "authorize_failure" and return
    end
    if logged_in?
      @token.authorize!(current_user)
    else
      @token.authorize!(@token.client_application.user)
    end
    @redirect_url = URI.parse(@token.oob? ? @token.client_application.callback_url || APP_CONFIG[:app_host] : @token.callback_url)

    unless @redirect_url.to_s.blank?
      @redirect_url.query = @redirect_url.query.blank? ?
                            "oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}" :
                            @redirect_url.query + "&oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}"
      redirect_to @redirect_url.to_s
    else
      render :action => "authorize_success"
    end
  end

end
{'fraction_non_alphanumeric': 0.11320754716981132, 'fraction_numerical': 0.0020964360587002098, 'mean_word_length': 3.2604166666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '6700711', 'n_tokens_mistral': 883, 'n_tokens_neox': 863, 'n_words': 154}