Sha256: bd558d569b99d1d9e2592af997dd6e0cfd0c1b847c9ad3fc6c5ad2e14eb95ccf

Contents?: true

Size: 1016 Bytes

Versions: 9

Compression:

Stored size: 1016 Bytes

Contents

module KktShoppe
  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 KktShoppe::Error do |e|
      @exception = e
      render :layout => 'kkt_shoppe/sub', :template => 'kkt_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[:kkt_shoppe_user_id]
        @user = User.find_by_id(session[:kkt_shoppe_user_id])
      end
    end
    
    def login_with_demo_mdoe
      if KktShoppe.settings.demo_mode?
        @user = User.first
      end
    end
    
    helper_method :current_user, :logged_in?
    
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kkt_shoppe-2.0.2 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-2.0.1 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-2.0.0 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-1.3.0 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-1.2.1 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-1.2.0 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-1.1.2 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-1.1.1 app/controllers/kkt_shoppe/application_controller.rb
kkt_shoppe-1.1.0 app/controllers/kkt_shoppe/application_controller.rb