You are here

function my_tfa_setup_form_submit in Two-factor Authentication (TFA) 7.2

Form submission handler.

File

./tfa.api.php, line 114
TFA API.

Code

function my_tfa_setup_form_submit($form, &$form_state) {
  $account = $form['account']['#value'];
  if (empty($form_state['storage'])) {

    // Start the TfaSetup process.
    $context = array(
      'uid' => $account->uid,
    );

    // Setup plugin class must be defined somehow (e.g. from a variable).
    $class = 'MyTfaPluginSetup';
    $setup_plugin = new $class($context);
    $tfa_setup = new TfaSetup($setup_plugin, $context);

    // Store TfaSetup process for multi-step.
    $form_state['storage']['tfa_setup'] = $tfa_setup;
    $form_state['rebuild'] = TRUE;
  }
  elseif (!empty($form_state['storage']['tfa_setup'])) {

    // Invoke plugin form submission.
    $tfa_setup = $form_state['storage']['tfa_setup'];
    if ($tfa_setup
      ->submitForm($form, $form_state)) {
      drupal_set_message(t('Setup complete'));
      $form_state['redirect'] = 'user';
    }
    else {

      // Setup isn't complete so rebuild.
      $form_state['rebuild'] = TRUE;
    }
  }
}