Module: Devise::Models::Recoverable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/models/recoverable.rb

Overview

Recoverable takes care of reseting the user password and send reset instructions Examples:

# resets the user password and save the record, true if valid passwords are given, otherwise false
User.find(1).reset_password!('password123', 'password123')

# only resets the user password, without saving the record
user = User.find(1)
user.reset_password('password123', 'password123')

# creates a new token and send it with instructions about how to reset the password
User.find(1).send_reset_password_instructions

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#reset_password!(new_password, new_password_confirmation) ⇒ Object

Update password saving the record and clearing token. Returns true if the passwords are valid and the record was saved, false otherwise.



21
22
23
24
25
26
# File 'lib/devise/models/recoverable.rb', line 21

def reset_password!(new_password, new_password_confirmation)
  self.password = new_password
  self.password_confirmation = new_password_confirmation
  clear_reset_password_token if valid?
  save
end

#send_reset_password_instructionsObject

Resets reset password token and send reset password instructions by email



29
30
31
32
# File 'lib/devise/models/recoverable.rb', line 29

def send_reset_password_instructions
  generate_reset_password_token!
  ::Devise.mailer.reset_password_instructions(self).deliver
end