You are here

function tfa_basic_setup_save_data in TFA Basic plugins 7

Save TFA settings for an account.

array(
  'plugins' => [
    'tfa_basic_totp',
  ],
  'sms' => FALSE,
  'status' => TRUE,
);

Parameters

object $account:

array $data TFA data:

2 calls to tfa_basic_setup_save_data()
tfa_basic_disable_form_submit in ./tfa_basic.pages.inc
Disable form submit.
tfa_basic_setup_form_submit in ./tfa_basic.pages.inc
Setup form submit.

File

./tfa_basic.module, line 427

Code

function tfa_basic_setup_save_data($account, $data = array()) {

  // Check if existing data and update.
  $existing = tfa_basic_get_tfa_data($account);
  if (!empty($existing['data'])) {
    $tfa_data = $existing['data'];
  }
  else {
    $tfa_data = array(
      'plugins' => '',
      'sms' => FALSE,
    );
  }
  if (isset($data['plugins'])) {
    $tfa_data['plugins'] = $data['plugins'];
  }
  if (isset($data['sms'])) {
    $tfa_data['sms'] = $data['sms'];
  }
  $status = 1;
  if (isset($data['status']) && $data['status'] === FALSE) {
    $tfa_data = array();
    $status = 0;
  }
  $record = array(
    'uid' => $account->uid,
    'saved' => REQUEST_TIME,
    'status' => $status,
    'data' => json_encode($tfa_data),
  );
  if (!empty($existing)) {
    drupal_write_record('tfa_user_settings', $record, 'uid');
  }
  else {
    drupal_write_record('tfa_user_settings', $record);
  }
}