function tfa_user in Two-factor Authentication (TFA) 6
Implements hook_user().
File
- ./
tfa.module, line 73 - Two-factor authentication for Drupal.
Code
function tfa_user($op, &$edit, &$account, $category = FALSE) {
global $user;
if ($op == 'login') {
if (variable_get('tfa_required', 0) && !user_access('skip tfa', $account) && !tfa_ready($account)) {
_tfa_logout();
drupal_goto('system/tfa-denied');
}
elseif (!user_access('skip tfa', $account) && tfa_ready($account)) {
// If a code is set and not marked accepted provide TFA code process.
$code = tfa_get_code($account->uid);
if (!empty($code) && $code['accepted']) {
// Code has been validated, delete and let login continue.
tfa_delete_code($account->uid);
drupal_goto('node');
}
else {
// Hold onto UID because $user will be replaced with Anonymous.
$uid = $user->uid;
// Destroy the current session to halt standard authentication process.
_tfa_logout();
$signatory = user_load(array(
'uid' => $uid,
));
// Generate and store code.
$code = tfa_generate_code($signatory);
tfa_store_code($signatory->uid, $code);
// Start send and redirection process.
tfa_tfa_process($signatory);
}
}
}
}