Class: Decidim::UpdatePassword

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/update_password.rb

Overview

Decidim command updates user’s password

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(form) ⇒ UpdatePassword

Updates a user’s password.

form - The form with the data.



11
12
13
# File 'app/commands/decidim/update_password.rb', line 11

def initialize(form)
  @form = form
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/commands/decidim/update_password.rb', line 15

def call
  return broadcast(:invalid) if form.invalid?

  current_user.password = form.password
  current_user.password_updated_at = Time.current

  if current_user.save
    broadcast(:ok)
  else
    broadcast(:invalid)
  end
end