module Devise::Models::Recoverable::ClassMethods

def reset_password_by_token(attributes = {})

Attributes must contain reset_password_token, password and confirmation
containing an error in reset_password_token attribute.
try saving the record. If not user is found, returns a new user
password. If a user is found and token is still valid, reset its password and automatically
Attempt to find a user by its reset_password_token to reset its
def reset_password_by_token(attributes = {})
  original_token       = attributes[:reset_password_token]
  reset_password_token = Devise.token_generator.digest(self, :reset_password_token, original_token)
  recoverable = find_or_initialize_with_error_by(:reset_password_token, reset_password_token)
  if recoverable.persisted?
    if recoverable.reset_password_period_valid?
      recoverable.reset_password(attributes[:password], attributes[:password_confirmation])
    else
      recoverable.errors.add(:reset_password_token, :expired)
    end
  end
  recoverable.reset_password_token = original_token if recoverable.reset_password_token.present?
  recoverable
end

def send_reset_password_instructions(attributes = {})

Attributes must contain the user's email
with an email not found error.
password instructions to it. If user is not found, returns a new user
Attempt to find a user by its email. If a record is found, send new
def send_reset_password_instructions(attributes = {})
  recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
  recoverable.send_reset_password_instructions if recoverable.persisted?
  recoverable
end

def with_reset_password_token(token)

If a user is not found, return nil
Attempt to find a user by password reset token. If a user is found, return it
def with_reset_password_token(token)
  reset_password_token = Devise.token_generator.digest(self, :reset_password_token, token)
  to_adapter.find_first(reset_password_token: reset_password_token)
end