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

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

Instance Method Summary collapse

Instance Method Details

#change_password!(new_password) ⇒ Object

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



108
109
110
111
112
# File 'lib/sorcery/model/submodules/reset_password.rb', line 108

def change_password!(new_password)
  clear_reset_password_token
  self.send(:"#{sorcery_config.password_attribute_name}=", new_password)
  sorcery_adapter.save
end

#deliver_reset_password_instructions!Object

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



97
98
99
100
101
102
103
104
105
# File 'lib/sorcery/model/submodules/reset_password.rb', line 97

def deliver_reset_password_instructions!
  config = sorcery_config
  # hammering protection
  return false if config.reset_password_time_between_emails.present? && 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.seconds.ago.utc
  self.class.sorcery_adapter.transaction do
    generate_reset_password_token!
    send_reset_password_email! unless config.reset_password_mailer_disabled
  end
end

#generate_reset_password_token!Object

generates a reset code with expiration



87
88
89
90
91
92
93
94
# File 'lib/sorcery/model/submodules/reset_password.rb', line 87

def generate_reset_password_token!
  config = sorcery_config
  attributes = {config.reset_password_token_attribute_name => TemporaryToken.generate_random_token,
                config.reset_password_email_sent_at_attribute_name => Time.now.in_time_zone}
  attributes[config.reset_password_token_expires_at_attribute_name] = Time.now.in_time_zone + config.reset_password_expiration_period if config.reset_password_expiration_period

  self.sorcery_adapter.update_attributes(attributes)
end