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
26
27
28
29
30
31
32
33
34
35
# File 'lib/devise-security/models/database_authenticatable_patch.rb', line 6

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

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

  result = if valid_password && new_password.present? && new_password_confirmation.present?
    update(params, *options)
  else
    self.assign_attributes(params, *options)

    if current_password.blank?
      self.errors.add(:current_password, :blank)
    elsif !valid_password
      self.errors.add(:current_password, :invalid)
    end

    self.errors.add(:password, :blank) if new_password.blank?

    if new_password_confirmation.blank?
      self.errors.add(:password_confirmation, :blank)
    end

    false
  end

  clean_up_passwords
  result
end