<commit_before>class Auth::GoogleController < ApplicationController

  def google
    access_token = request.env['omniauth.auth']['credentials']['token']
    name, email = GoogleIntegration::Profile.fetch_name_and_email(access_token)
    if session[:role].present?
      google_sign_up(name, email, session[:role], access_token)
    else
      google_login(email, access_token)
    end
  end


  private

  def google_login(email, access_token)
    user = User.find_by(email: email.downcase)
    if user.present?
      sign_in(user)
      TestForEarnedCheckboxesWorker.perform_async(user.id)
      GoogleIntegration::Classroom::Main.pull_and_save_data(user, access_token)
      redirect_to profile_path
    else
      redirect_to new_account_path
    end
  end


  def google_sign_up(name, email, role, access_token)
    user = User.find_or_initialize_by(email: email.downcase)
    if user.new_record?
      user.attributes = {signed_up_with_google: true, name: name, role: role}
      user.save
      sign_in(user)
      ip = request.remote_ip
      GoogleIntegration::Classroom::Main.pull_and_save_data(user, access_token)
      AccountCreationCallbacks.new(user, ip).trigger
      user.subscribe_to_newsletter
      if user.role == 'teacher'
        render 'accounts/new'
      end
    end
    if user.errors.any?
      redirect_to new_account_path
    else
      user.update(signed_up_with_google: true)
      GoogleIntegration::Classroom::Main.pull_and_save_data(user, access_token)
      redirect_to profile_path
    end
  end
end<commit_msg>Return after rendering or redirecting in google controller.<commit_after>class Auth::GoogleController < ApplicationController

  def google
    access_token = request.env['omniauth.auth']['credentials']['token']
    name, email = GoogleIntegration::Profile.fetch_name_and_email(access_token)
    if session[:role].present?
      google_sign_up(name, email, session[:role], access_token)
    else
      google_login(email, access_token)
    end
  end


  private

  def google_login(email, access_token)
    user = User.find_by(email: email.downcase)
    if user.present?
      sign_in(user)
      TestForEarnedCheckboxesWorker.perform_async(user.id)
      GoogleIntegration::Classroom::Main.pull_and_save_data(user, access_token)
      redirect_to profile_path
    else
      redirect_to new_account_path
    end
  end


  def google_sign_up(name, email, role, access_token)
    user = User.find_or_initialize_by(email: email.downcase)
    if user.new_record?
      user.attributes = {signed_up_with_google: true, name: name, role: role}
      user.save
      sign_in(user)
      ip = request.remote_ip
      GoogleIntegration::Classroom::Main.pull_and_save_data(user, access_token)
      AccountCreationCallbacks.new(user, ip).trigger
      user.subscribe_to_newsletter
      if user.role == 'teacher'
        render 'accounts/new'
        return
      end
    end
    if user.errors.any?
      redirect_to new_account_path
      return
    else
      user.update(signed_up_with_google: true)
      GoogleIntegration::Classroom::Main.pull_and_save_data(user, access_token)
      redirect_to profile_path
      return
    end
  end
end
{'fraction_non_alphanumeric': 0.08388312912346843, 'fraction_numerical': 0.0, 'mean_word_length': 3.6144927536231886, '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': '1547792', 'n_tokens_mistral': 998, 'n_tokens_neox': 983, 'n_words': 185}