You are here

public function MobileNumber::sendVerification in Mobile Number 7

Send verification code to mobile number.

Parameters

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 MobileNumberInterface::sendVerification

File

src/MobileNumber.php, line 215

Class

MobileNumber
Class MobileNumber handles mobile number validation and verification.

Code

public function sendVerification($message, $code, $token_data = array()) {
  $message = t($message, array(
    '!code' => $code,
    '!site_name' => variable_get('site_name', $_SERVER['SERVER_NAME']),
  ));
  if (module_exists('token')) {
    $message = token_replace($message, $token_data);
  }
  flood_register_event('mobile_number_sms', $this::SMS_ATTEMPTS_INTERVAL, $this->callableNumber);
  flood_register_event('mobile_number_sms_ip', $this::SMS_ATTEMPTS_INTERVAL * 5);
  if (mobile_number_send_sms($this->callableNumber, $message)) {
    $token = $this
      ->registerVerificationCode($code, $this->callableNumber);
    $_SESSION['mobile_number_verification'][$this->callableNumber] = array(
      'token' => $token,
      'verified' => FALSE,
    );
    return $token;
  }
  return FALSE;
}