<commit_before># frozen_string_literal: true

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def omniauth_login(provider)
    redirect_to new_user_session_path, notice: t('omniauth.access_denied') unless user.present?
    user.accept_invitation! if invitation_token
    upload_avatar(omniauth_avatar)
    flash[:notice] = I18n.t('devise.omniauth_callbacks.success',
                            kind: t("navigation.#{provider}"))
    sign_in_and_redirect @user, event: :authentication
  end

  private

  def user
    @user ||= User.find_for_oauth(request.env['omniauth.auth'])
  end

  def omniauth_avatar
    request.env['omniauth.auth']&.[]('info')&.[]('image')
  end

  def update_needed?(omniauth_avatar)
    return if omniauth_avatar.nil?

    user.third_party_avatar != omniauth_avatar
  end

  # returns the invitation token passed in with the callback url
  def invitation_token
    request.env.dig('omniauth.params', 'invitation_token')
  end

  def upload_avatar(omniauth_avatar)
    return unless update_needed?(omniauth_avatar)

    user.third_party_avatar = omniauth_avatar
    user.remote_avatar_url = omniauth_avatar
    user.save!
  end<commit_msg>change from omniauth to navigation<commit_after># frozen_string_literal: true

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def omniauth_login(provider)
    redirect_to new_user_session_path, notice: t('omniauth.access_denied') unless user.present?
    user.accept_invitation! if invitation_token
    upload_avatar(omniauth_avatar)
    flash[:notice] = I18n.t('devise.omniauth_callbacks.success',
                            kind: t("navigation.#{provider}"))
    sign_in_and_redirect @user, event: :authentication
  end

  private

  def find_auth_translation(provider)
    if provider == 'google'
      return t('navigation.google')
    else if provider == 'facebook'
      return t('navigation.facebook')
    end
  end

  def user
    @user ||= User.find_for_oauth(request.env['omniauth.auth'])
  end

  def omniauth_avatar
    request.env['omniauth.auth']&.[]('info')&.[]('image')
  end

  def update_needed?(omniauth_avatar)
    return if omniauth_avatar.nil?

    user.third_party_avatar != omniauth_avatar
  end

  # returns the invitation token passed in with the callback url
  def invitation_token
    request.env.dig('omniauth.params', 'invitation_token')
  end

  def upload_avatar(omniauth_avatar)
    return unless update_needed?(omniauth_avatar)

    user.third_party_avatar = omniauth_avatar
    user.remote_avatar_url = omniauth_avatar
    user.save!
  end
{'fraction_non_alphanumeric': 0.09487080601619745, 'fraction_numerical': 0.0015426147319706903, 'mean_word_length': 4.261663286004056, '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': '5893150', 'n_tokens_mistral': 872, 'n_tokens_neox': 836, 'n_words': 160}