Module: Devise::Models::DatabaseAuthenticatablePatch

Defined in:
lib/devise-security/models/database_authenticatable_patch.rb

Instance Method Summary collapse

Instance Method Details

#update_with_password(params, *options) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/devise-security/models/database_authenticatable_patch.rb', line 6

def update_with_password(params, *options)
  current_password = params.delete(:current_password)

  new_password = params[:password]
  new_password_confirmation = params[:password_confirmation]

  result = if valid_password?(current_password) && new_password.present? && new_password_confirmation.present?
    update(params, *options)
  else
    self.assign_attributes(params, *options)
    self.valid?
    self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
    self.errors.add(:password, new_password.blank? ? :blank : :invalid)
    self.errors.add(:password_confirmation, new_password_confirmation.blank? ? :blank : :invalid)
    false
  end

  clean_up_passwords
  result
end