Module: Devise::Models::Recoverable::ClassMethods

Defined in:
lib/devise/models/recoverable.rb

Instance Method Summary collapse

Instance Method Details

#reset_password_by_token(attributes = {}) ⇒ Object

Attempt to find a user by it’s reset_password_token to reset its password. If a user is found and token is still valid, reset its password and automatically try saving the record. If not user is found, returns a new user containing an error in reset_password_token attribute. Attributes must contain reset_password_token, password and confirmation



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/devise/models/recoverable.rb', line 113

def reset_password_by_token(attributes={})
  recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[: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
end

#reset_password_tokenObject

Generate a token checking if one does not already exist in the database.



104
105
106
# File 'lib/devise/models/recoverable.rb', line 104

def reset_password_token
  generate_token(:reset_password_token)
end

#send_reset_password_instructions(attributes = {}) ⇒ Object

Attempt to find a user by it’s email. If a record is found, send new password instructions to it. If not user is found, returns a new user with an email not found error. Attributes must contain the user email



97
98
99
100
101
# File 'lib/devise/models/recoverable.rb', line 97

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