Module Devise::Models::Recoverable
In: lib/devise/models/recoverable.rb

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

Options

Recoverable adds the following options to devise_for:

  * +reset_password_keys+: the keys you want to use when recovering the password for an account

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

Methods

Classes and Modules

Module Devise::Models::Recoverable::ClassMethods

Public Instance methods

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

Checks if the reset password token sent is within the limit time. We do this by calculating if the difference between today and the sending date does not exceed the confirm in time configured. Returns true if the resource is not responding to reset_password_sent_at at all. reset_password_within is a model configuration, must always be an integer value.

Example:

  # reset_password_within = 1.day and reset_password_sent_at = today
  reset_password_period_valid?   # returns true

  # reset_password_within = 5.days and reset_password_sent_at = 4.days.ago
  reset_password_period_valid?   # returns true

  # reset_password_within = 5.days and reset_password_sent_at = 5.days.ago
  reset_password_period_valid?   # returns false

  # reset_password_within = 0.days
  reset_password_period_valid?   # will always return false

Resets reset password token and send reset password instructions by email

Protected Instance methods

Removes reset_password token

Generates a new random token for reset password

Resets the reset password token with and save the record without validating

[Validate]