You are here

function tfa_basic_tfa_context_alter in TFA Basic plugins 7

Alters tfa_context array to set plugins from user settings.

File

./tfa_basic.module, line 249

Code

function tfa_basic_tfa_context_alter(&$context) {

  // $context can be empty during beginning of TFA process.
  if (empty($context)) {
    return;
  }
  $account = user_load($context['uid']);
  $tfa_data = tfa_basic_get_tfa_data($account);

  // Remove SMS plugin if enabled and mobile number is not available.
  $number = tfa_basic_get_mobile_number($account);
  if (empty($tfa_data['data']['sms']) || !$number) {
    $fallback_plugins = array();
    if (isset($context['plugins']['fallback'])) {
      foreach ($context['plugins']['fallback'] as $plugin) {
        if ($plugin !== 'tfa_basic_sms') {
          $fallback_plugins[] = $plugin;
        }
      }
    }

    // Remove SMS from validation if set.
    if ('tfa_basic_sms' == $context['plugins']['validate'] && !empty($fallback_plugins)) {
      $context['plugins']['validate'] = array_shift($fallback_plugins);
    }
    $context['plugins']['fallback'] = $fallback_plugins;
  }
}