Class: Decidim::Verifications::Sms::MobilePhoneForm

Inherits:
AuthorizationHandler show all
Defined in:
decidim-verifications/app/forms/decidim/verifications/sms/mobile_phone_form.rb

Overview

A form object to be used when public users want to get verified using their phone.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods inherited from AuthorizationHandler

#authorization_attributes, #duplicate, #form_attributes, handler_for, handler_name, #metadata, #to_partial_path, #transferrable?, #unique?, #verification_attachment

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, #map_model, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#handler_nameObject



14
15
16
# File 'decidim-verifications/app/forms/decidim/verifications/sms/mobile_phone_form.rb', line 14

def handler_name
  "sms"
end

#mobile_phone_numberObject

When there is a phone number, sanitize it allowing only numbers and +.



26
27
28
29
30
# File 'decidim-verifications/app/forms/decidim/verifications/sms/mobile_phone_form.rb', line 26

def mobile_phone_number
  return unless super

  super.gsub(/[^+0-9]/, "")
end

#unique_idObject

A mobile phone can only be verified once but it should be private.



19
20
21
22
23
# File 'decidim-verifications/app/forms/decidim/verifications/sms/mobile_phone_form.rb', line 19

def unique_id
  Digest::MD5.hexdigest(
    "#{mobile_phone_number}-#{Rails.application.secrets.secret_key_base}"
  )
end

#verification_metadataObject

The verification metadata to validate in the next step.



33
34
35
36
37
38
# File 'decidim-verifications/app/forms/decidim/verifications/sms/mobile_phone_form.rb', line 33

def 
  {
    verification_code:,
    code_sent_at: Time.current
  }
end