Module: Devise::Models::Authenticatable::ClassMethods
- Defined in:
- lib/devise/models/authenticatable.rb
Instance Method Summary collapse
-
#authenticate(attributes = {}) ⇒ Object
Authenticate a user based on email and password.
-
#find_or_initialize_with_error_by_email(email) ⇒ Object
Attempt to find a user by it’s email.
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
66 67 68 69 |
# File 'lib/devise/models/authenticatable.rb', line 66 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.
73 74 75 76 77 78 79 |
# File 'lib/devise/models/authenticatable.rb', line 73 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 |