Class: Decidim::Initiatives::ValidateMobilePhone

Inherits:
Rectify::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

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

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 doesn't have an authorization for sms in ok

    status or the phone number associated with its
    authorization doesn't 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