You are here

public function MobileNumber::verifyCode in Mobile Number 7

Verifies input code matches code sent to user.

Parameters

string $code: Input code.

string|NULL $token: Verification token, if verification code was not sent in this session.

Return value

bool TRUE if matches

Overrides MobileNumberInterface::verifyCode

File

src/MobileNumber.php, line 263

Class

MobileNumber
Class MobileNumber handles mobile number validation and verification.

Code

public function verifyCode($code, $token = NULL) {
  if ($code && ($this
    ->getToken() || $token)) {
    $token = $token ? $token : $this
      ->getToken();
    $hash = $this
      ->codeHash($token, $code, $this->callableNumber);
    $query = db_select('mobile_number_verification', 'm');
    $query
      ->fields('m', array(
      'token',
    ))
      ->condition('token', $token)
      ->condition('timestamp', time() - 60 * 60 * 24, '>')
      ->condition('verification_code', $hash);
    $result = $query
      ->execute()
      ->fetchAssoc();
    if ($result) {
      $_SESSION['mobile_number_verification'][$this->callableNumber]['verified'] = TRUE;
      return TRUE;
    }
    flood_register_event('mobile_number_verification', $this::VERIFY_ATTEMPTS_INTERVAL, $this->callableNumber);
    return FALSE;
  }
  return FALSE;
}