function tfa_user_login in Two-factor Authentication (TFA) 7
Same name and namespace in other branches
- 7.2 tfa.module \tfa_user_login()
Implements hook_user_login().
File
- ./
tfa.module, line 77 - Two-factor authentication for Drupal.
Code
function tfa_user_login(&$edit, $account) {
global $user;
if (variable_get('tfa_required', 0) && !user_access('skip tfa', $account) && !tfa_ready($account)) {
_tfa_logout();
drupal_set_message(t('Login disallowed till your account is setup for TFA. Contact a site administrator.'), 'error');
drupal_goto('user');
}
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);
$query = drupal_get_query_parameters();
if (empty($query['destination'])) {
$_GET['destination'] = 'node';
}
}
else {
// Destroy the current session to halt standard authentication process.
_tfa_logout();
// Generate and store code.
$code = tfa_generate_code($account);
tfa_store_code($account->uid, $code);
// Start TFA process.
tfa_tfa_process($account);
}
}
}