Created
February 22, 2010 14:47
-
-
Save joshk/311119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_with_password(params={}) | |
current_password = params.delete(:current_password) | |
params.delete(:password) if params[:password].blank? | |
params.delete(:password_confirmation) if params[:password_confirmation].blank? | |
skip_password_check = !(current_password.present? || params[:password] || params[:password_confirmation]) | |
result = if skip_password_check || valid_password?(current_password) | |
update_attributes(params) | |
else | |
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid) | |
self.attributes = params | |
false | |
end | |
clean_up_passwords unless result | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment