def authenticate(email, password, client_ip)
      return nil unless Incline::EmailValidator.valid?(email)
      email = email.downcase

      # If an engine is registered for the email domain, then use it.
      engine = get_auth_engine(email)
      if engine
        return engine.authenticate(email, password, client_ip)
      end

      # Otherwise we will be using the database.
      user = User.find_by(email: email)
      if user
        # user must be enabled and the password must match.
        unless user.enabled?
          add_failure_to user, '(DB) account disabled', client_ip
          return nil
        end
        if user.authenticate(password)
          add_success_to user, '(DB)', client_ip
          return user
        else
          add_failure_to user, '(DB) invalid password', client_ip
          return nil
        end
      end
      add_failure_to email, 'invalid email', client_ip
      nil
    end
def authenticate(email, password, client_ip)
      return nil unless Incline::EmailValidator.valid?(email)
      email = email.downcase

      # If an engine is registered for the email domain, then use it.
      engine = get_auth_engine(email)
      if engine
        return engine.authenticate(email, password, client_ip)
      end

      # Otherwise we will be using the database.
      user = User.find_by(email: email)
      if user
        # user must be enabled and the password must match.
        unless user.enabled?
          add_failure_to user, '(DB) account disabled', client_ip
          return nil
        end
        if user.authenticate(password)
          add_success_to user, '(DB)', client_ip
          return user
        else
          add_failure_to user, '(DB) invalid password', client_ip
          return nil
        end
      end
      add_failure_to email, 'invalid email', client_ip
      nil
    end
Creates a new user manager.

 The user manager itself takes no options, however options will be passed to
 any registered authentication engines when they are instantiated.

 The options can be used to pre-register engines and provide configuration for them.
 The engines will have specific configurations, but the UserManager class recognizes
 the 'engines' key.

     {
       :engines => {
         'example.com' => {
           :engine => MySuperAuthEngine.new(...)
         },
         'example.org' => {
           :engine => 'incline_ldap/auth_engine',
           :config => {
             :host => 'ldap.example.org',
             :port => 636,
             :base_dn => 'DC=ldap,DC=example,DC=org'
           }
         }
       }
     }

 When an 'engines' key is processed, the configuration options for the engines are pulled
 from the subkeys.  Once the processing of the 'engines' key is complete, it will be removed
 from the options hash so any engines registered in the future will not receive the extra options.

 Attempts to authenticate the user and returns the model on success.