<commit_before>class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  skip_before_filter :set_locale

  def facebook
    omniauth = request.env['omniauth.auth']
    @user = User.
      select('users.*').
      joins('JOIN authorizations ON authorizations.user_id = users.id').
      joins('JOIN oauth_providers ON oauth_providers.id = authorizations.oauth_provider_id').
      where("authorizations.uid = :uid AND oauth_providers.name = :provider", {uid: omniauth[:uid], provider: p.name}).
      first

    if @user
      puts "already authorized"
    end

    @user ||= User.create_with_omniauth(omniauth, current_user)

    puts @user.inspect

    flash[:notice] = I18n.t("devise.omniauth_callbacks.success", kind: p.name.capitalize)

    puts "sigining "
    sign_in @user, event: :authentication
    if @user.email
      puts "has email"
      redirect_to(session[:return_to] || root_path)
      session[:return_to] = nil
    else
      puts "set email"
      render 'users/set_email'
    end
  end

  def self.add_providers
    # OauthProvider.all.each do |p|
    #   define_method p.name.downcase do
    #     omniauth = request.env['omniauth.auth']
    #     @user = User.
    #       select('users.*').
    #       joins('JOIN authorizations ON authorizations.user_id = users.id').
    #       joins('JOIN oauth_providers ON oauth_providers.id = authorizations.oauth_provider_id').
    #       where("authorizations.uid = :uid AND oauth_providers.name = :provider", {uid: omniauth[:uid], provider: p.name}).
    #       first || User.create_with_omniauth(omniauth, current_user)

    #     flash[:notice] = I18n.t("devise.omniauth_callbacks.success", kind: p.name.capitalize)
    #     sign_in @user, event: :authentication
    #     if @user.email
    #       redirect_to(session[:return_to] || root_path)
    #       session[:return_to] = nil
    #     else
    #       render 'users/set_email'
    #     end

    #   end
    # end
  end
end<commit_msg>Putting stuff back<commit_after>class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  skip_before_filter :set_locale
  def self.add_providers
    OauthProvider.all.each do |p|
      define_method p.name.downcase do
        omniauth = request.env['omniauth.auth']
        @user = User.
          select('users.*').
          joins('JOIN authorizations ON authorizations.user_id = users.id').
          joins('JOIN oauth_providers ON oauth_providers.id = authorizations.oauth_provider_id').
          where("authorizations.uid = :uid AND oauth_providers.name = :provider", {uid: omniauth[:uid], provider: p.name}).
          first || User.create_with_omniauth(omniauth, current_user)

        flash[:notice] = I18n.t("devise.omniauth_callbacks.success", kind: p.name.capitalize)
        sign_in @user, event: :authentication
        if @user.email
          redirect_to(session[:return_to] || root_path)
          session[:return_to] = nil
        else
          render 'users/set_email'
        end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11389897655992076, 'fraction_numerical': 0.0019808517662594917, 'mean_word_length': 2.9096774193548387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5621389', 'n_tokens_mistral': 994, 'n_tokens_neox': 964, 'n_words': 190}