You are here

function tfa_code_form_submit in Two-factor Authentication (TFA) 7

Same name and namespace in other branches
  1. 6 tfa.pages.inc \tfa_code_form_submit()

Submit handler for TFA login form.

File

./tfa.pages.inc, line 70
tfa.pages.inc

Code

function tfa_code_form_submit($form, &$form_state) {
  global $user;
  $uid = $form_state['values']['uid'];
  $account = user_load($uid);
  $edit = array();
  $user = $account;

  // Update the user table timestamp noting user has logged in.
  $user->login = REQUEST_TIME;
  db_update('users')
    ->fields(array(
    'login' => $user->login,
  ))
    ->condition('uid', $user->uid)
    ->execute();

  // Regenerate the session ID to prevent against session fixation attacks.
  drupal_session_regenerate();

  // Mark code as accepted to avoid repeating TFA process.
  tfa_accept_code($account->uid);
  watchdog('tfa', 'TFA login code accepted for @name. Session opened.', array(
    '@name' => $user->name,
  ));

  // Truncate flood for user.
  flood_clear_event('tfa_send');
  flood_clear_event('tfa_validate');
  user_module_invoke('login', $edit, $user);
}