You are here

public function MobileNumberUtil::sendVerification in Mobile Number 2.0.x

Same name and namespace in other branches
  1. 8 src/MobileNumberUtil.php \Drupal\mobile_number\MobileNumberUtil::sendVerification()

Send verification code to mobile number.

Parameters

\libphonenumber\PhoneNumber $mobile_number: Phone number object.

string $message: Drupal translatable string.

string $code: Code to send.

array $token_data: Token variables to be used with token_replace().

Return value

bool Success flag.

Overrides MobileNumberUtilInterface::sendVerification

File

src/MobileNumberUtil.php, line 260

Class

MobileNumberUtil
Turns a render array into a HTML string.

Namespace

Drupal\mobile_number

Code

public function sendVerification(PhoneNumber $mobile_number, $message, $code, $token_data = []) {
  $message = t($message);
  $message = str_replace('!code', $code, $message);
  $message = str_replace('!site_name', $this->configFactory
    ->get('system.site')
    ->get('name'), $message);
  $message = $this->token
    ->replace($message, $token_data);
  $this->flood
    ->register('mobile_number_sms', $this::SMS_ATTEMPTS_INTERVAL, $this
    ->getCallableNumber($mobile_number));
  $this->flood
    ->register('mobile_number_sms_ip', $this::SMS_ATTEMPTS_INTERVAL * 5);
  if ($this
    ->sendSms($this
    ->getCallableNumber($mobile_number), $message)) {
    $token = $this
      ->registerVerificationCode($mobile_number, $code);
    $_SESSION['mobile_number_verification'][$this
      ->getCallableNumber($mobile_number)] = [
      'token' => $token,
      'verified' => FALSE,
    ];
    return $token;
  }
  return FALSE;
}