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



15
16
17
18
19
# File 'lib/devise/models/recoverable.rb', line 15

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



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

def reset_password(new_password, new_password_confirmation)
  self.password = new_password
  self.password_confirmation = new_password_confirmation
end

#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.



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

def reset_password!(new_password, new_password_confirmation)
  reset_password(new_password, 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



36
37
38
39
# File 'lib/devise/models/recoverable.rb', line 36

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