Module: Devise::Models::AafRcAuthenticatable::ClassMethods

Defined in:
lib/devise_aaf_rc_authenticatable/model.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_with_aaf_rc(attributes = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/devise_aaf_rc_authenticatable/model.rb', line 33

def authenticate_with_aaf_rc(attributes={})

  auth_key = self.authentication_keys.first

  auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? attributes['mail'].downcase : attributes['mail']

  resource = find_for_authentication(auth_key => auth_key_value)

  if (resource.nil? && !Devise.aaf_rc_create_user)
    Rails.logger.info("User(#{auth_key_value}) not found.  Not configured to create the user.")
    return nil
  end

  if (resource.nil? && Devise.aaf_rc_create_user)
    Rails.logger.info("Creating user(#{auth_key_value}).")
    resource = new
    save_user_aaf_rc_attributes(resource, attributes)
    resource.aaf_rc_before_save if resource.respond_to?(:aaf_rc_before_save)
    resource.save
  end

  resource
end