function legal_user_login in Legal 7
Same name and namespace in other branches
- 8 legal.module \legal_user_login()
- 7.2 legal.module \legal_user_login()
- 2.0.x legal.module \legal_user_login()
Implements hook_user_login().
File
- ./
legal.module, line 445 - Module file for Legal.
Code
function legal_user_login(&$edit, $account) {
global $user;
global $language;
// If this profile belongs to user 1 or if it has an exempt user role we don't
// display Terms & Conditions.
if (legal_user_is_exempt($user)) {
return;
}
$legal_accept_every_login = variable_get('legal_accept_every_login', '0');
// Get last accepted version for this account
$legal_account = legal_get_accept($user->uid);
// If no version has been accepted yet, get version with current language revision.
if (!isset($legal_account['version'])) {
$conditions = legal_get_conditions($language->language);
// No conditions set yet.
if (empty($conditions['conditions'])) {
return;
}
}
else {
$conditions = legal_get_conditions($legal_account['language']);
// No conditions set yet.
if (empty($conditions['conditions'])) {
return;
}
// Check latest version of T&C has been accepted.
$accepted = legal_version_check($user->uid, $conditions['version'], $conditions['revision'], $legal_account);
if ($accepted) {
if ($legal_accept_every_login == 0) {
return;
}
if ($legal_accept_every_login == 1 && isset($_SESSION['legal']['legal_login']) && $_SESSION['legal']['legal_login'] == 1) {
return;
}
}
}
$uid = $user->uid;
// Log the user out and regenerate the Drupal session.
module_invoke_all('user_logout', $user);
drupal_session_regenerate();
// We have to use $GLOBALS to unset a global variable.
$user = drupal_anonymous_user();
$query = NULL;
// Deal with destination from password reset one time login link,
// by creating a new one time login link and setting it as the destination
// after the T&Cs have been accepted.
if (arg(0) == 'user' && arg(1) == 'reset') {
$token = drupal_random_key();
// This is a new, anonymous-user session.
$_SESSION['pass_reset_' . $uid] = $token;
$query = array(
'destination' => "user/{$uid}/edit?pass-reset-token={$token}",
);
user_cookie_save(array(
'legal_pass_reset' => TRUE,
));
}
if (!empty($_REQUEST['destination'])) {
$query = array(
'destination' => $_REQUEST['destination'],
);
}
unset($_GET['destination']);
$result = db_select('users', 'u')
->fields('u')
->condition('uid', $uid)
->range(0, 1)
->execute()
->fetchAllAssoc('uid');
$signatory = array_pop($result);
$token = drupal_random_key();
$hash = user_pass_rehash($signatory->pass, $token, $signatory->login, $uid);
user_cookie_save(array(
'legal_hash' => $hash,
'legal_id' => $uid,
));
$query['token'] = $token;
drupal_goto('legal_accept', array(
'query' => $query,
));
}