You are here

public function MobileNumberUtil::registerVerificationCode in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/MobileNumberUtil.php \Drupal\mobile_number\MobileNumberUtil::registerVerificationCode()

Registers code for mobile number and returns it's token.

Parameters

\libphonenumber\PhoneNumber $mobile_number: Phone number object.

string $code: Access code.

Return value

string 43 character token.

Overrides MobileNumberUtilInterface::registerVerificationCode

1 call to MobileNumberUtil::registerVerificationCode()
MobileNumberUtil::sendVerification in src/MobileNumberUtil.php
Send verification code to mobile number.

File

src/MobileNumberUtil.php, line 288

Class

MobileNumberUtil
Turns a render array into a HTML string.

Namespace

Drupal\mobile_number

Code

public function registerVerificationCode(PhoneNumber $mobile_number, $code) {
  $time = time();
  $token = \Drupal::csrfToken()
    ->get(rand(0, 999999999) . $time . 'mobile verification token' . $this
    ->getCallableNumber($mobile_number));
  $hash = $this
    ->codeHash($mobile_number, $token, $code);
  \Drupal::database()
    ->insert('mobile_number_verification')
    ->fields([
    'token' => $token,
    'timestamp' => $time,
    'verification_code' => $hash,
  ])
    ->execute();
  return $token;
}