Module: AuthHelpers::Model::Recoverable::ClassMethods
- Defined in:
- lib/auth_helpers/model/recoverable.rb
Instance Method Summary collapse
-
#find_and_reset_password(options = {}) ⇒ Object
Receives a hash with perishable_token, password and password confirmation.
-
#find_and_send_reset_password_instructions(options = {}) ⇒ Object
Receives a hash with email and tries to find a record to resend reset password instructions.
Instance Method Details
#find_and_reset_password(options = {}) ⇒ Object
Receives a hash with perishable_token, password and password confirmation. If the password cannot be reset (confirmation fails, for example), it returns an object with errors.
50 51 52 53 54 55 56 57 |
# File 'lib/auth_helpers/model/recoverable.rb', line 50 def find_and_reset_password(={}) if recoverable = self.find_using_perishable_token([:perishable_token]) recoverable.reset_password!([:password], [:password_confirmation]) recoverable else AuthHelpers.new_with_perishable_token_error(self, :invalid_reset_password, ) end end |
#find_and_send_reset_password_instructions(options = {}) ⇒ Object
Receives a hash with email and tries to find a record to resend reset password instructions. If the record can’t be found, it sets the appropriate error messages and return the object.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/auth_helpers/model/recoverable.rb', line 33 def find_and_send_reset_password_instructions(={}) recoverable = AuthHelpers.find_or_initialize_by_unless_blank(self, :email, [:email]) if recoverable.new_record? recoverable.errors.add(:email, :not_found, ) else recoverable.reset_perishable_token! AuthHelpers::Notifier.deliver_reset_password(recoverable) end return recoverable end |