Sha256: b395ae8dfe1d06979818b5b76af28f0f8cf7418f8ebb4560baa17de4d798fa42

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module AuthN
  module Model
    def self.included(object)
      object.extend ClassMethods
    end

    module ClassMethods
      def has_authentication(o = {})
        options = AuthN.config.table.any? ? o.merge!(AuthN.config) : o
        config.merge! options
      end

      def config=(options)
        @@config = options
      end

      def config
        @@config ||= AuthN::Config.new
      end

      def authenticate(identifiers = {})
        # Extract the password from the identifiers
        password = identifiers.delete AuthN.config.login_password_key

        # Find the documents that match the criteria
        criteria = send AuthN.config.model_critera_method, identifiers

        # Get the first document that matches the criteria
        instance = criteria.first

        # Check to see if the instance exists and if a password was given
        if instance && password
          # Check to see if the instance can authenticate with password
          instance.authenticate(password) ? instance : false
        end

        # Return instance if account was found and password matched
        # Return false if account was found and password didn't match
        # Return nil if account wasn't found OR password wasn't given
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authn-2.6.0 lib/authn/model.rb
authn-2.4.0 lib/authn/model.rb
authn-2.0.1 lib/authn/model.rb
authn-2.0.0 lib/authn/model.rb