Sha256: 1be1376e0c43a611845ce82771eade49d7db429e0c775048c4bf6e508f061d6a

Contents?: true

Size: 1.25 KB

Versions: 23

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require 'singleton'

module SimpleAuthenticationPlugin
  include Praxis::PluginConcern

  class Plugin < Praxis::Plugin
    include Singleton

    def initialize
      @options = { config_file: 'config/authentication.yml' }
      super
    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
        Plugin.authenticate(controller.request) if action.authentication_required
      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

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.40 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.39 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.38 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.37 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.36 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.35 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.34 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.33 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.32 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.31 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.30 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.29 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.28 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.27 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.26 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.25 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.24 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.23 spec/support/spec_simple_authentication_plugin.rb
praxis-2.0.pre.22 spec/support/spec_simple_authentication_plugin.rb