Sha256: 8dc1beb8c984083e5aeb3c518434c662ae92481ae8139ff8c1b3fc733f864f3d

Contents?: true

Size: 991 Bytes

Versions: 18

Compression:

Stored size: 991 Bytes

Contents

module Shoppe
  class ApplicationController < ActionController::Base
    
    before_filter :login_required
    
    rescue_from ActiveRecord::DeleteRestrictionError do |e|
      redirect_to request.referer || root_path, :alert => e.message
    end
    
    rescue_from Shoppe::Error do |e|
      @exception = e
      render :layout => 'shoppe/sub', :template => 'shoppe/shared/error'
    end

    private

    def login_required
      unless logged_in?
        redirect_to login_path
      end
    end

    def logged_in?
      current_user.is_a?(User)
    end
    
    def current_user
      @current_user ||= login_from_session || login_with_demo_mdoe || :false
    end

    def login_from_session
      if session[:shoppe_user_id]
        @user = User.find_by_id(session[:shoppe_user_id])
      end
    end
    
    def login_with_demo_mdoe
      if Shoppe.settings.demo_mode?
        @user = User.first
      end
    end
    
    helper_method :current_user, :logged_in?
    
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
shoppe-1.1.0 app/controllers/shoppe/application_controller.rb
shoppe-1.0.9 app/controllers/shoppe/application_controller.rb
shoppe-1.0.8 app/controllers/shoppe/application_controller.rb
kylekthompson-shoppe-1.0.7 app/controllers/shoppe/application_controller.rb
shoppe-1.0.7 app/controllers/shoppe/application_controller.rb
shoppe-1.0.6 app/controllers/shoppe/application_controller.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/shoppe-1.0.5/app/controllers/shoppe/application_controller.rb
shoppe-1.0.5 app/controllers/shoppe/application_controller.rb
shoppe-1.0.3 app/controllers/shoppe/application_controller.rb
shoppe-1.0.2 app/controllers/shoppe/application_controller.rb
shoppe-1.0.1 app/controllers/shoppe/application_controller.rb
shoppe-1.0.0 app/controllers/shoppe/application_controller.rb
shoppe-0.0.21 app/controllers/shoppe/application_controller.rb
shoppe-0.0.20 app/controllers/shoppe/application_controller.rb
shoppe-0.0.19 app/controllers/shoppe/application_controller.rb
shoppe-0.0.18 app/controllers/shoppe/application_controller.rb
shoppe-0.0.17 app/controllers/shoppe/application_controller.rb
shoppe-0.0.16 app/controllers/shoppe/application_controller.rb