Sha256: 57eec64f3adcef008fea69667730c93c89ab0c0721a90343a69b460475cbbd0a

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

module ActionController
  class Base

    around_filter :assign_current_controller
    helper_method :current_rich_cms_admin, :current_rich_cms_admin_name, :rich_cms_authenticated_class, :rich_cms_authentication_inputs
    
    def assign_current_controller
      ::Rich::Cms::Engine.current_controller = self
      yield
    ensure
      ::Rich::Cms::Engine.current_controller = nil
    end

    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
    
    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
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rich_cms-1.0.0 lib/rich/cms/actionpack/action_controller/base.rb