Class: Decidim::Initiatives::ValidateMobilePhone

Inherits:
Command
  • Object
show all
Defined in:
decidim-initiatives/app/commands/decidim/initiatives/validate_mobile_phone.rb

Overview

Command to check if mobile phone has an authorization and deliver sms code

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, user) ⇒ ValidateMobilePhone

Public: Initializes the command.

form - A MobilePhoneForm. user - The user which mobile phone must be validated.



12
13
14
15
# File 'decidim-initiatives/app/commands/decidim/initiatives/validate_mobile_phone.rb', line 12

def initialize(form, user)
  @form = form
  @user = user
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid. Returns the verification metadata of

    the form.
    
  • :invalid if the user does not have an authorization for sms in ok

    status or the phone number associated with its
    authorization does not match the form number.
    


24
25
26
27
28
29
30
# File 'decidim-initiatives/app/commands/decidim/initiatives/validate_mobile_phone.rb', line 24

def call
  return broadcast(:invalid) unless authorized? && phone_match?

  generate_code

  broadcast(:ok, @verification_metadata)
end