Sha256: 29bd32a0847e2e9cf29a38346879fbad5d786294229c9cb6a41afb6271f9348c

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

require 'spree/core/validators/email' if Spree.version.to_f < 3.5
module Spree::CheckoutControllerDecorator
  def self.prepended(base)
    base.before_action :check_authorization
    base.before_action :check_registration, except: [:registration, :update_registration]
  end

  def registration
    @user = Spree::User.new
  end

  def update_registration
    if order_params[:email] =~ Devise.email_regexp && current_order.update_attribute(:email, order_params[:email])
      redirect_to spree.checkout_state_path(:address)
    else
      flash[:error] = t(:email_is_invalid, scope: [:errors, :messages])
      @user = Spree::User.new
      render 'registration'
    end
  end

  private

  def order_params
    params[:order].present? ? params.require(:order).permit(:email) : {}
  end

  def skip_state_validation?
    %w(registration update_registration).include?(params[:action])
  end

  def check_authorization
    authorize!(:edit, current_order, cookies.signed[:guest_token])
  end

  # Introduces a registration step whenever the +registration_step+ preference is true.
  def check_registration
    return unless Spree::Auth::Config[:registration_step]
    return if spree_current_user || current_order.email
    store_location
    redirect_to spree.checkout_registration_path
  end
end
Spree::CheckoutController.prepend(Spree::CheckoutControllerDecorator)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_auth_devise-4.0.1 lib/controllers/frontend/spree/checkout_controller_decorator.rb
spree_auth_devise-4.1.0.rc1 lib/controllers/frontend/spree/checkout_controller_decorator.rb
spree_auth_devise-4.0.0 lib/controllers/frontend/spree/checkout_controller_decorator.rb
spree_auth_devise-4.0.0.rc2 lib/controllers/frontend/spree/checkout_controller_decorator.rb
spree_auth_devise-4.0.0.rc1 lib/controllers/frontend/spree/checkout_controller_decorator.rb