Module: AuthN::Model::ClassMethods

Defined in:
lib/authn/model.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(identifiers = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/authn/model.rb', line 20

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

  # 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

#configObject



16
17
18
# File 'lib/authn/model.rb', line 16

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

#config=(options) ⇒ Object



12
13
14
# File 'lib/authn/model.rb', line 12

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

#has_authentication(options = {}) ⇒ Object



8
9
10
# File 'lib/authn/model.rb', line 8

def has_authentication(options = {})
  merge_config_with options
end