Module: Devise::Models::Authenticatable::ClassMethods

Defined in:
lib/devise/models/authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(attributes = {}) ⇒ Object

Authenticate a user based on email and password. Returns the authenticated user if it’s valid or nil. Attributes are :email and :password



77
78
79
80
# File 'lib/devise/models/authenticatable.rb', line 77

def authenticate(attributes={})
  authenticatable = find_by_email(attributes[:email])
  authenticatable if authenticatable.try(:valid_password?, attributes[:password])
end

#find_or_initialize_with_error_by_email(email) ⇒ Object

Attempt to find a user by it’s email. If not user is found, returns a new user with an email not found error.



84
85
86
87
88
89
90
# File 'lib/devise/models/authenticatable.rb', line 84

def find_or_initialize_with_error_by_email(email)
  perishable = find_or_initialize_by_email(email)
  if perishable.new_record?
    perishable.errors.add(:email, :not_found, :default => 'not found')
  end
  perishable
end