You are here

public function MobileNumberItem::verify in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldType/MobileNumberItem.php \Drupal\mobile_number\Plugin\Field\FieldType\MobileNumberItem::verify()

Performs verification, assuming verification token and code were set. Adds to flood if failed. Will not attempt to verify if number is already verified.

Return value

bool|int|null TRUE if verification is successful, FALSE if wrong code provided, NULL if code or token not provided, and -1 if does not pass flood check.

1 call to MobileNumberItem::verify()
MobileNumberItem::preSave in src/Plugin/Field/FieldType/MobileNumberItem.php
Defines custom presave behavior for field values.

File

src/Plugin/Field/FieldType/MobileNumberItem.php, line 463

Class

MobileNumberItem
Plugin implementation of the 'mobile_number' field type.

Namespace

Drupal\mobile_number\Plugin\Field\FieldType

Code

public function verify() {

  /** @var \Drupal\mobile_number\MobileNumberUtilInterface $util */
  $util = \Drupal::service('mobile_number.util');
  $values = $this
    ->getValue();
  $token = !empty($values['verification_token']) ? $values['verification_token'] : NULL;
  $code = !empty($values['verification_code']) ? $values['verification_code'] : NULL;
  if ($this
    ->isVerified()) {
    return TRUE;
  }
  $mobile_number = $this
    ->getMobileNumber();
  if (!empty($token) && !empty($code) && $mobile_number) {
    if ($util
      ->checkFlood($mobile_number)) {
      return $util
        ->verifyCode($mobile_number, $code, $token);
    }
    else {
      return -1;
    }
  }
  else {
    return NULL;
  }
}