<commit_before>require 'open_food_network/error_logger'

class UserRegistrationsController < Spree::UserRegistrationsController
  I18N_SCOPE = 'devise.user_registrations.spree_user'.freeze

  before_filter :set_checkout_redirect, only: :create

  # POST /resource/sign_up
  def create
    @user = build_resource(params[:spree_user])
    if resource.save
      session[:spree_user_signup] = true
      session[:confirmation_return_url] = params[:return_url]
      associate_user

      respond_to do |format|
        format.html do
          set_flash_message(:success, :signed_up_but_unconfirmed)
          redirect_to after_sign_in_path_for(@user)
        end
        format.js do
          render json: { email: @user.email }
        end
      end
    else
      render_error(@user.errors)
    end
  rescue StandardError => error
    OpenFoodNetwork::ErrorLogger.notify(error)
    render_error(message: I18n.t('unknown_error', scope: I18N_SCOPE))
  end

  private

  def render_error(errors = {})
    clean_up_passwords(resource)
    respond_to do |format|
      format.html do
        render :new<commit_msg>Refactor user registrations controller, early return to reduce indentation<commit_after>require 'open_food_network/error_logger'

class UserRegistrationsController < Spree::UserRegistrationsController
  I18N_SCOPE = 'devise.user_registrations.spree_user'.freeze

  before_filter :set_checkout_redirect, only: :create

  # POST /resource/sign_up
  def create
    @user = build_resource(params[:spree_user])
    unless resource.save
      return render_error(@user.errors)
    end

    session[:spree_user_signup] = true
    session[:confirmation_return_url] = params[:return_url]
    associate_user

    respond_to do |format|
      format.html do
        set_flash_message(:success, :signed_up_but_unconfirmed)
        redirect_to after_sign_in_path_for(@user)
      end
      format.js do
        render json: { email: @user.email }
      end
    end
  rescue StandardError => error
    OpenFoodNetwork::ErrorLogger.notify(error)
    render_error(message: I18n.t('unknown_error', scope: I18N_SCOPE))
  end

  private

  def render_error(errors = {})
    clean_up_passwords(resource)
    respond_to do |format|
      format.html do
        render :new
{'fraction_non_alphanumeric': 0.08090185676392574, 'fraction_numerical': 0.005305039787798408, 'mean_word_length': 3.5995934959349594, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7384119', 'n_tokens_mistral': 724, 'n_tokens_neox': 702, 'n_words': 137}