Sha256: 667d606bbe4b79eecbbc2df22e9f84ca18bc559775ceba523cdeed8c5632f7fb

Contents?: true

Size: 1.23 KB

Versions: 36

Compression:

Stored size: 1.23 KB

Contents

require 'singleton'

module SimpleAuthenticationPlugin
  include Praxis::PluginConcern

  class Plugin < Praxis::Plugin
    include Singleton

    def initialize
      @options = {config_file: 'config/authentication.yml'}
    end

    def config_key
      :authentication
    end

    def prepare_config!(node)
      node.attributes do
        attribute :authentication_default, Attributor::Boolean, default: false
      end
    end

    def self.authenticate(request)
      request.current_user == 'guest'
    end

  end


  module Request
    def current_user
      'guest'
    end
  end

  module Controller
    extend ActiveSupport::Concern

    included do
      before :action do |controller|
        action = controller.request.action
        if action.authentication_required
          Plugin.authenticate(controller.request)
        end
      end
    end

  end


  module ActionDefinition
    extend ActiveSupport::Concern

    included do
      decorate_docs do |action, docs|
        docs[:authentication_required] = action.authentication_required
      end
    end

    def requires_authentication(value)
      @authentication_required = value
    end

    def authentication_required
      @authentication_required ||= false
    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.17 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.16 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.15 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.14 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.13 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.12 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.11 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.10 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.9 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.8 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.7 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.6 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.5 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.4 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.3 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.2 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.1 spec/support/spec_simple_authentication_plugin.rb
praxis-0.22.pre.2 spec/support/spec_simple_authentication_plugin.rb
praxis-0.22.pre.1 spec/support/spec_simple_authentication_plugin.rb