Sha256: 958abef506a2a7059007d8d96aafe242273e57deb428612805f72eb7e6af4872

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

Contents

module Comable
  module SigninAction
    class << self
      def prepended(base)
        base.instance_eval do
          before_filter :ensure_signed_in_or_guest, except: [:signin, :guest]

          helper_method :resource
          helper_method :resource_name
          helper_method :devise_mapping
        end
      end
    end

    def guest
      if @order.state?(:cart) ? @order.next_state : @order.save
        redirect_to next_order_path
      else
        render :signin
      end
    end

    private

    def ensure_signed_in_or_guest
      return if @order.email
      store_location
      redirect_to comable.signin_order_path
    end

    def resource
      current_comable_user
    end

    def resource_name
      :user
    end

    def devise_mapping
      Devise.mappings[resource_name]
    end

    # orderride OrdersController#order_params
    def order_params
      return super unless action_name.in? %w( signin guest )
      order_params_for_signin
    end

    def order_params_for_signin
      params.fetch(:order, {}).permit(
        :email
      )
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
comable-frontend-0.7.1 app/controllers/concerns/comable/signin_action.rb
comable-frontend-0.7.0 app/controllers/concerns/comable/signin_action.rb
comable-frontend-0.7.0.beta2 app/controllers/concerns/comable/signin_action.rb
comable-frontend-0.7.0.beta1 app/controllers/concerns/comable/signin_action.rb
comable-frontend-0.6.0 app/controllers/concerns/comable/signin_action.rb
comable_frontend-0.5.0 app/controllers/concerns/comable/signin_action.rb
comable_frontend-0.4.2 app/controllers/concerns/comable/signin_action.rb
comable_frontend-0.4.1 app/controllers/concerns/comable/signin_action.rb
comable_frontend-0.4.0 app/controllers/concerns/comable/signin_action.rb