Sha256: dd4121b0b65919e419375fac2153f51d7c2515b33615a7e054602f826223d948

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

require 'spree/core/validators/email'
Spree::CheckoutController.class_eval do
  before_filter :check_authorization
  before_filter :check_registration, :except => [:registration, :update_registration]

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

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

  private
    def order_params
      params[:order] ? 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 or current_order.email
      store_location
      redirect_to spree.checkout_registration_path
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_auth_devise-3.1.0 lib/controllers/frontend/spree/checkout_controller_decorator.rb
spree_auth_devise-3.0.6 lib/controllers/frontend/spree/checkout_controller_decorator.rb
spree_auth_devise-3.0.5 lib/controllers/frontend/spree/checkout_controller_decorator.rb