Sha256: 2b5d8bd6433f2bcc7c22adaa1bd8fc4f5b7710a07cf69d0f15c6ebcc9397ba09

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

module Landable
  AuthenticationFailedError = Class.new(StandardError)

  module AuthenticationService
    def self.call(username, password)
      strategies = Landable.configuration.authenticators

      strategies.each do |strategy|
        ident = strategy.call username, password
        return ident if ident
      end

      raise AuthenticationFailedError
    end

    class EchoAuthenticator
      def self.call(username, password)
        new(nil, nil).call(username, password)
      end

      def initialize(username, password)
        @username = username
        @password = password
      end

      def call(username, password)
        return unless acceptable_environment?
        return echo_author(username) if @username.nil? && password != 'fail'
        return echo_author(username) if @username == username && @password == password
      end

      private

      def acceptable_environment?
        defined?(::Rails) && (Rails.env.development? || Rails.env.test?)
      end

      def echo_author(username)
        { username: username, email: "#{username}@example.com",
          first_name: 'Trogdor', last_name: 'McBurninator' }
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
landable-1.13.1 app/services/landable/authentication_service.rb
landable-1.12.3 app/services/landable/authentication_service.rb
landable-1.12.2 app/services/landable/authentication_service.rb
landable-1.12.1 app/services/landable/authentication_service.rb
landable-1.11.1 app/services/landable/authentication_service.rb
landable-1.11.0 app/services/landable/authentication_service.rb
landable-1.10.0.rc2 app/services/landable/authentication_service.rb
landable-1.10.0.rc1 app/services/landable/authentication_service.rb
landable-1.9.2 app/services/landable/authentication_service.rb
landable-1.9.1 app/services/landable/authentication_service.rb
landable-1.9.0 app/services/landable/authentication_service.rb
landable-1.9.0.rc2 app/services/landable/authentication_service.rb
landable-1.9.0.rc1 app/services/landable/authentication_service.rb
landable-1.8.0 app/services/landable/authentication_service.rb
landable-1.7.1.rc1 app/services/landable/authentication_service.rb
landable-1.7.0 app/services/landable/authentication_service.rb