You are here

function tfa_admin_settings in Two-factor Authentication (TFA) 7

Same name and namespace in other branches
  1. 6 tfa.pages.inc \tfa_admin_settings()
  2. 7.2 tfa.admin.inc \tfa_admin_settings()

Admin settings form.

1 string reference to 'tfa_admin_settings'
tfa_menu in ./tfa.module
Implements hook_menu().

File

./tfa.pages.inc, line 109
tfa.pages.inc

Code

function tfa_admin_settings() {
  $form = array();

  // Choose communication channel.
  $channels = array();
  $hook = 'tfa_api';
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    if (function_exists($function)) {
      $channel = $function();
      $channels[$module] = $channel;
      $send_methods[$module] = $channel['title'];
    }
  }
  $default_channel = variable_get('tfa_channel', 'sms');
  $form['tfa_channel'] = array(
    '#type' => 'select',
    '#title' => t('Channel'),
    '#options' => $send_methods,
    '#default_value' => $default_channel,
    '#description' => t('Choose the channel to communicate the TFA login code.'),
  );

  // If the channel does not define a 'address callback' method default to field.
  // Controlled via Form API #states.
  $form['tfa_phone_field'] = array(
    '#type' => 'container',
    '#children' => t('<div class="error messages">A phone field is required for the TFA process. Add a user field for phone number storage to continue. Consult the <a href="!url">help documentation for more info</a>.</div>', array(
      '!url' => url('admin/help/tfa'),
    )),
    '#states' => array(
      'visible' => array(
        ':input[name="tfa_channel"]' => array(
          'value' => 'sms',
        ),
      ),
    ),
  );
  $instances = field_info_instances('user');
  if (!empty($instances['user'])) {

    //drupal_set_message(t('A phone field is required for the TFA process. Add a user field for phone number storage to continue. Consult the <a href="!url">help documentation for more info</a>.', array('!url' => url('admin/help/tfa'))), 'error');
    $options = array();
    foreach ($instances['user'] as $name => $field) {
      $options[$name] = $field['label'];
    }

    // Change to select field.
    unset($form['tfa_phone_field']['#children']);
    $form['tfa_phone_field']['#type'] = 'select';
    $form['tfa_phone_field']['#default_value'] = variable_get('tfa_phone_field', '');
    $form['tfa_phone_field']['#options'] = $options;
    $form['tfa_phone_field']['#description'] = t('Choose the field that stores phone numbers.');
  }
  $form['tfa_required'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require TFA process'),
    '#default_value' => variable_get('tfa_required', 0),
    '#description' => t('Require TFA to login except for accounts that have permission to "Skip TFA". Note, any account that is not setup for TFA (and is not set to skip TFA) will not be able to login.'),
  );
  $form['tfa_send_message'] = array(
    '#type' => 'textfield',
    '#title' => t('Message'),
    '#default_value' => variable_get('tfa_send_message', 'Login code'),
    '#description' => t('Text to prepend before the TFA login code. Plain text only.'),
  );
  $form['tfa_code_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Code length'),
    '#default_value' => variable_get('tfa_code_length', 6),
    '#description' => t('Length of the TFA login code.'),
  );
  $form['tfa_code_ttl'] = array(
    '#type' => 'textfield',
    '#title' => t('Code expiration time'),
    '#default_value' => variable_get('tfa_code_ttl', 86400),
    '#description' => t('Length of time the TFA login code is valid.'),
  );
  return system_settings_form($form);
}