Module: AuthHelpers::Model::Updatable
- Defined in:
- lib/auth_helpers/model/updatable.rb
Overview
Hacks into update attributes to dael with email, email confirmation, password and password confirmation. If the e-mail changes, it resends the confirmation instructions if the confirmable module is also included.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
9 10 11 12 13 |
# File 'lib/auth_helpers/model/updatable.rb', line 9 def self.included(base) base.send :attr_accessor, :email_confirmation, :password_confirmation base.send :attr_accessible, :email, :email_confirmation, :password, :password_confirmation base.send :validates_confirmation_of, :email, :password end |
Instance Method Details
#update_attributes(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/auth_helpers/model/updatable.rb', line 15 def update_attributes() .delete(:email) if [:email] == self.email .delete(:email_confirmation) if [:email_confirmation].blank? .delete(:password) if [:password].blank? || self.valid_password?([:password]) .delete(:password_confirmation) if [:password_confirmation].blank? # Force confirmations (if confirmation is nil, it won't validate, it has to be at least blank) [:email_confirmation] ||= '' if [:email] [:password_confirmation] ||= '' if [:password] if super() if [:email] && self.respond_to?(:send_confirmation_instructions) self.send_confirmation_instructions(:update) end return true end return false end |