Module: DataMapper::Is::Authenticatable::ClassMethods

Defined in:
lib/dm-is-authenticatable/is/authenticatable.rb

Overview

Class methods.

Instance Method Summary collapse

Instance Method Details

#authenticate(attributes) ⇒ DataMapper::Resource?

Finds and authenticates a resource.

Parameters:

  • attributes (Hash)

    The attributes to search with.

Options Hash (attributes):

  • :password (String)

    The clear-text password to authenticate with.

Returns:

  • (DataMapper::Resource, nil)

    The authenticated resource. If the resource could not be found, or the password did not match, nil will be returned.



38
39
40
41
42
43
44
45
# File 'lib/dm-is-authenticatable/is/authenticatable.rb', line 38

def authenticate(attributes)
  password = attributes.delete(:password)
  resource = self.first(attributes)

  if (resource && resource.has_password?(password))
    return resource
  end
end