Module: Sorcery::Model::Submodules::ResetPassword::InstanceMethods

Defined in:
lib/sorcery/model/submodules/reset_password.rb

Instance Method Summary collapse

Instance Method Details

#deliver_reset_password_instructions!Object

generates a reset code with expiration and sends an email to the user.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sorcery/model/submodules/reset_password.rb', line 64

def deliver_reset_password_instructions!
  config = sorcery_config
  # hammering protection
  return if config.reset_password_time_between_emails && self.send(config.reset_password_email_sent_at_attribute_name) && self.send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.ago.utc
  self.send(:"#{config.reset_password_token_attribute_name}=", generate_random_token)
  self.send(:"#{config.reset_password_token_expires_at_attribute_name}=", Time.now.utc + config.reset_password_expiration_period) if config.reset_password_expiration_period
  self.send(:"#{config.reset_password_email_sent_at_attribute_name}=", Time.now.utc)
  self.class.transaction do
    self.save!(:validate => false)
    generic_send_email(:reset_password_email_method_name, :reset_password_mailer)
  end
end

#reset_password!(params) ⇒ Object

Clears token and tries to update the new password for the user.



78
79
80
81
# File 'lib/sorcery/model/submodules/reset_password.rb', line 78

def reset_password!(params)
  clear_reset_password_token
  update_attributes(params)
end