Module: Devise::Models::Recoverable::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#reset_password!(attributes = {}) ⇒ Object

Attempt to find a user by it’s reset_password_token to reset it’s password. If a user is found, reset it’s password and automatically try saving the record. If not user is found, returns a new user containing an error in reset_password_token attribute. Attributes must contain reset_password_token, password and confirmation



76
77
78
79
80
81
82
83
84
# File 'lib/devise/models/recoverable.rb', line 76

def reset_password!(attributes={})
  recoverable = find_or_initialize_by_reset_password_token(attributes[:reset_password_token])
  if recoverable.new_record?
    recoverable.errors.add(:reset_password_token, :invalid)
  else
    recoverable.reset_password!(attributes[:password], attributes[:password_confirmation])
  end
  recoverable
end

#send_reset_password_instructions(attributes = {}) ⇒ Object

Attempt to find a user by it’s email. If a record is found, send new password instructions to it. If not user is found, returns a new user with an email not found error. Attributes must contain the user email



65
66
67
68
69
# File 'lib/devise/models/recoverable.rb', line 65

def send_reset_password_instructions(attributes={})
  recoverable = find_or_initialize_with_error_by_email(attributes[:email])
  recoverable.send_reset_password_instructions unless recoverable.new_record?
  recoverable
end