Sha256: 7b4e8264d90a10a123c95e7c793d4d4e78bb7185509eb832b9298c308e220ffc

Contents?: true

Size: 1.69 KB

Versions: 8

Compression:

Stored size: 1.69 KB

Contents

module ActionController
  class Base

    around_filter :prepare_rich_cms
    
    def prepare_rich_cms
      ::Rich::Cms::Engine.current_controller = self
      yield
    ensure
      ::Rich::Cms::Engine.current_controller = nil
    end
    
    view_path = File.join File.dirname(__FILE__), "..", "..", "..", "..", "app", "views"
    if respond_to? :append_view_path
      self.append_view_path view_path
    elsif respond_to? :view_paths
      self.view_paths << view_path
    end
    
    helper_method :current_rich_cms_admin, :current_rich_cms_admin_name, :rich_cms_authenticated_class, :rich_cms_authentication_inputs

    def require_current_rich_cms_admin
      unless current_rich_cms_admin
        redirect_to root_url
        return false
      end
    end

    def current_rich_cms_admin
      case rich_cms_auth.logic
      when :authlogic
        return @current_rich_cms_admin if defined?(@current_rich_cms_admin)
        @current_rich_cms_admin_session ||= rich_cms_authenticated_class.find
        @current_rich_cms_admin = @current_rich_cms_admin_session.try rich_cms_auth.specs[:class_name].demodulize.underscore
      end
    end

    def current_rich_cms_admin_name
      current_rich_cms_admin[rich_cms_auth.specs[:identifier]] if current_rich_cms_admin
    end
    
    def rich_cms_auth
      ::Rich::Cms::Engine.authentication
    end
    
    def rich_cms_authenticated_class
      case rich_cms_auth.logic
      when :authlogic
        "#{rich_cms_auth.specs[:class_name]}Session".constantize
      end
    end
    
    def rich_cms_authentication_inputs
      case rich_cms_auth.logic
      when :authlogic
        rich_cms_auth.specs[:inputs] || [:email, :password]
      end
    end
    
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rich_cms-2.0.7 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.6 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.5 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.4 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.3 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.2 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.1 lib/rich/cms/actionpack/action_controller/base.rb
rich_cms-2.0.0 lib/rich/cms/actionpack/action_controller/base.rb