Problem/Motivation

Need to add phone verification validation on registration page, while user creating a account on the site.
if he has already used then we need to show a message to the user "This number is already in use and cannot be assigned to more than one account"

Steps to reproduce

Proposed resolution

add form alter in twilio.module file.
$form['actions']['submit']['#validate'][] = 'twilio_register_validate';

/**
 * Custom validation function for phone numbers during registration.
 */
function twilio_register_validate($form, FormStateInterface $form_state) {
  $value = $form_state->getValues();

  $num_verify = \Drupal::service('twilio.sms')->twilio_verify_number($value['number']);
  
 
  // Something has been entered but is non numeric.
  if (!is_numeric($value['number'])) {
    $form_state->setErrorByName('number', t('You must enter a valid phone number'));
    return false;
  }
  
  if ($num_verify) {
    $form_state->setErrorByName('number', t('This number is already in use and cannot be assigned to more than one account'));
  
  return false;
  }
  
  return true;
}

Issue fork twilio-3358354

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    1 hidden branch
  • 8.x.2.x Comparechanges, plain diff MR !6

Comments

shashank5563 created an issue. See original summary.

shashank5563’s picture

Issue summary: View changes
rajan kumar’s picture

Status: Needs work » Needs review
StatusFileSize
new2.1 KB

Attached patch for restrict user to enter duplicate phone number during user registration.

shashank5563’s picture

Status: Needs review » Needs work
shashank5563’s picture

Status: Needs work » Fixed

@rajan, I have applied your patch.

Thank you for your support.

shashank5563’s picture

Status: Fixed » Closed (fixed)