Module: Devise::Models::Recoverable

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



17
18
19
20
21
# File 'lib/devise/models/recoverable.rb', line 17

def self.included(base)
  base.class_eval do
    extend ClassMethods
  end
end

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.



25
26
27
28
29
30
# File 'lib/devise/models/recoverable.rb', line 25

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



33
34
35
36
# File 'lib/devise/models/recoverable.rb', line 33

def send_reset_password_instructions
  generate_reset_password_token!
  ::DeviseMailer.deliver_reset_password_instructions(self)
end