Module: Devise::Models::Imapable::ClassMethods

Defined in:
lib/devise_imapable/model.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_with_imap(attributes = {}) ⇒ Object

Authenticate a user based on configured attribute keys. Returns the authenticated user if it’s valid or nil.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/devise_imapable/model.rb', line 34

def authenticate_with_imap(attributes={})
  return unless attributes[:email].present?
  conditions = attributes.slice(:email)

  unless conditions[:email] && conditions[:email].include?('@') && Devise.default_email_suffix
    conditions[:email] = "#{conditions[:email]}@#{Devise.default_email_suffix}"
  end

  resource = find_for_imap_authentication(conditions) || new(conditions)

  if resource.try(:valid_imap_authentication?, attributes[:password])
     resource.new_record? ? create(conditions) : resource
  end
end