Module: Sorcery::Model::Submodules::ResetPassword::InstanceMethods
- Defined in:
- lib/sorcery/model/submodules/reset_password.rb
Instance Method Summary collapse
-
#change_password(new_password, raise_on_failure: false) ⇒ Object
Clears token and tries to update the new password for the user.
- #change_password!(new_password) ⇒ Object
-
#deliver_reset_password_instructions! ⇒ Object
Generates a reset code with expiration and sends an email to the user.
-
#generate_reset_password_token! ⇒ Object
Generates a reset code with expiration.
-
#increment_password_reset_page_access_counter ⇒ Object
Increment access_count_to_reset_password_page attribute.
-
#reset_password_reset_page_access_counter ⇒ Object
Reset access_count_to_reset_password_page attribute into 0.
Instance Method Details
#change_password(new_password, raise_on_failure: false) ⇒ Object
Clears token and tries to update the new password for the user.
133 134 135 136 137 |
# File 'lib/sorcery/model/submodules/reset_password.rb', line 133 def change_password(new_password, raise_on_failure: false) clear_reset_password_token send(:"#{sorcery_config.password_attribute_name}=", new_password) sorcery_adapter.save raise_on_failure: raise_on_failure end |
#change_password!(new_password) ⇒ Object
139 140 141 142 143 |
# File 'lib/sorcery/model/submodules/reset_password.rb', line 139 def change_password!(new_password) raise ArgumentError, 'Blank password passed to change_password!' if new_password.blank? change_password(new_password, raise_on_failure: true) end |
#deliver_reset_password_instructions! ⇒ Object
Generates a reset code with expiration and sends an email to the user.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sorcery/model/submodules/reset_password.rb', line 103 def deliver_reset_password_instructions! mail = false config = sorcery_config # hammering protection if config.reset_password_time_between_emails.present? && send(config.reset_password_email_sent_at_attribute_name) && send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.seconds.ago.utc return false end self.class.sorcery_adapter.transaction do generate_reset_password_token! mail = send_reset_password_email! unless config.reset_password_mailer_disabled end mail end |
#generate_reset_password_token! ⇒ Object
Generates a reset code with expiration
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sorcery/model/submodules/reset_password.rb', line 91 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 } if config.reset_password_expiration_period attributes[config.reset_password_token_expires_at_attribute_name] = Time.now.in_time_zone + config.reset_password_expiration_period end sorcery_adapter.update_attributes(attributes) end |
#increment_password_reset_page_access_counter ⇒ Object
Increment access_count_to_reset_password_page attribute. For example, access_count_to_reset_password_page attribute is over 1, which means the user doesn’t have a right to access.
121 122 123 |
# File 'lib/sorcery/model/submodules/reset_password.rb', line 121 def increment_password_reset_page_access_counter sorcery_adapter.increment(sorcery_config.reset_password_page_access_count_attribute_name) end |
#reset_password_reset_page_access_counter ⇒ Object
Reset access_count_to_reset_password_page attribute into 0. This is expected to be used after sending an instruction email.
127 128 129 130 |
# File 'lib/sorcery/model/submodules/reset_password.rb', line 127 def reset_password_reset_page_access_counter send(:"#{sorcery_config.reset_password_page_access_count_attribute_name}=", 0) sorcery_adapter.save end |