You are here

function tfa_start_context in Two-factor Authentication (TFA) 7.2

Start context for TFA.

Parameters

object $account: User account.

Return value

array array( 'uid' => 9, 'plugins' => array( 'validate' => 'tfa_my_send_plugin', 'login' => array('tfa_my_login_plugin'), 'fallback' => array('tfa_my_recovery_plugin'), ),

3 calls to tfa_start_context()
tfa_get_process in ./tfa.module
Get Tfa object in the account's current context.
tfa_login_submit in ./tfa.module
Login submit handler to determine if TFA process is applicable.
tfa_user_login in ./tfa.module
Implements hook_user_login().

File

./tfa.module, line 109
Two-factor authentication for Drupal.

Code

function tfa_start_context($account) {
  $plugins = array(
    'validate' => '',
    'fallback' => array(),
    'login' => array(),
  );
  $api = module_invoke_all('tfa_api');

  // Add login plugins.
  foreach (variable_get('tfa_login_plugins', array()) as $key) {
    if (array_key_exists($key, $api)) {
      $plugins['login'][] = $key;
    }
  }

  // Add validate.
  $validate = variable_get('tfa_validate_plugin', '');
  if (!empty($validate) && array_key_exists($validate, $api)) {
    $plugins['validate'] = $validate;
  }

  // Add fallback plugins.
  foreach (variable_get('tfa_fallback_plugins', array()) as $key) {
    if (array_key_exists($key, $api)) {
      $plugins['fallback'][] = $key;
    }
  }

  // Allow other modules to modify TFA context.
  $context = array(
    'uid' => $account->uid,
    'plugins' => $plugins,
  );
  drupal_alter('tfa_context', $context);
  tfa_set_context($account, $context);
  return $context;
}