You are here

protected function MobileNumberTfa::sendCode in Mobile Number 7

Send the code via the client.

Return value

bool Where sending sms was successful.

2 calls to MobileNumberTfa::sendCode()
MobileNumberTfa::begin in src/MobileNumberTfa.php
Begin TFA process.
MobileNumberTfa::submitForm in src/MobileNumberTfa.php
Submit form callback.

File

src/MobileNumberTfa.php, line 161
Contains MobileNumberTfa.

Class

MobileNumberTfa
Class MobileNumberTfa is a validation and sending plugin for TFA.

Code

protected function sendCode() {
  $this->code = $this->mobileNumber
    ->generateVerificationCode($this->codeLength);
  try {
    $message = variable_get('mobile_number_tfa_message', MOBILE_NUMBER_DEFAULT_SMS_MESSAGE);
    if (!($this->verificationToken = $this->mobileNumber
      ->sendVerification($message, $this->code, array(
      'user' => user_load($this->context['uid']),
    )))) {
      return FALSE;
    }

    // @todo Consider storing date_sent or date_updated to inform user.
    watchdog('mobile_number_tfa', 'TFA validation code sent to user !uid', array(
      '!uid' => $this->context['uid'],
    ), WATCHDOG_INFO);
    return TRUE;
  } catch (Exception $e) {
    watchdog('mobile_number_tfa', 'Send message error to user !uid. Status code: @code, message: @message', array(
      '!uid' => $this->context['uid'],
      '@code' => $e
        ->getCode(),
      '@message' => $e
        ->getMessage(),
    ), WATCHDOG_ERROR);
    return FALSE;
  }
}