Sha256: 52daa01b0e110be79019fb5250d5cdbbe0a6205b01196facf568d3d68a4b7d9e

Contents?: true

Size: 954 Bytes

Versions: 10

Compression:

Stored size: 954 Bytes

Contents

module Tienda
  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 Tienda::Error do |e|
      @exception = e
      render layout: 'tienda/sub', template: 'tienda/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[:tienda_user_id]
        @user = User.find_by_id(session[:tienda_user_id])
      end
    end

    def login_with_demo_mdoe
      if Tienda.settings.demo_mode?
        @user = User.first
      end
    end

    helper_method :current_user, :logged_in?

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tienda-2.1.3 app/controllers/tienda/application_controller.rb
tienda-2.1.2 app/controllers/tienda/application_controller.rb
tienda-2.1.1 app/controllers/tienda/application_controller.rb
tienda-2.1.0 app/controllers/tienda/application_controller.rb
tienda-2.0.2 app/controllers/tienda/application_controller.rb
tienda-2.0.1 app/controllers/tienda/application_controller.rb
tienda-1.1.2 app/controllers/tienda/application_controller.rb
tienda-1.1.1 app/controllers/tienda/application_controller.rb
tienda-1.1.0 app/controllers/tienda/application_controller.rb
tienda-1.0.0 app/controllers/tienda/application_controller.rb