function logintoboggan_user in LoginToboggan 6
Same name and namespace in other branches
- 5 logintoboggan.module \logintoboggan_user()
Implementation of hook_user().
File
- ./
logintoboggan.module, line 1078 - Logintoboggan Module
Code
function logintoboggan_user($op, &$edit, &$user_edit, $category = NULL) {
global $user;
if ($op == 'form' && $category == 'account') {
// User is editing their own account settings, or user admin
// is editing their account.
if ($user->uid == $user_edit->uid || user_access('administer users')) {
// Display link to re-send validation e-mail.
// Re-validate link appears if:
// 1. Users can create their own password.
// 2. User is still in the validating role.
// 3. Users can create accounts without admin approval.
// 4. The validating role is not the authorized user role.
$validating_id = logintoboggan_validating_id();
if (!variable_get('user_email_verification', TRUE) && array_key_exists($validating_id, $user_edit->roles) && variable_get('user_register', 1) == 1 && $validating_id > DRUPAL_AUTHENTICATED_RID) {
$form['revalidate'] = array(
'#type' => 'fieldset',
'#title' => t('Account validation'),
'#weight' => -10,
);
$form['revalidate']['revalidate_link'] = array(
'#value' => l(t('re-send validation e-mail'), 'toboggan/revalidate/' . $user_edit->uid),
);
return $form;
}
}
}
elseif ($op == 'login' && variable_get('logintoboggan_login_successful_message', 0)) {
drupal_set_message(theme('lt_login_successful_message', $user_edit));
}
elseif ($op == 'load') {
// Just loaded the user into $user_edit.
// If the user has the pre-auth role, unset the authenticated role
_logintoboggan_user_roles_alter($user_edit);
}
elseif ($op == 'validate') {
// If login with mail is enabled...
if (variable_get('logintoboggan_login_with_email', 0)) {
$uid = isset($user_edit->uid) ? $user_edit->uid : 0;
// Check that no user is using this name for their email address.
if (isset($edit['name']) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s') AND uid <> %d", $edit['name'], $uid))) {
form_set_error('name', t('This name has already been taken by another user.'));
}
// Check that no user is using this email address for their name.
if (isset($edit['mail']) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER('%s') AND uid <> %d", $edit['mail'], $uid))) {
form_set_error('mail', t('This e-mail has already been taken by another user.'));
}
}
}
elseif ($op == 'update') {
// Only perform this check if:
// 1. An admin is editing the account.
// 2. Admin approval is required for new user accounts.
if (user_access('administer users') && variable_get('user_register', 1) == 2) {
// Test here for a valid pre-auth -- if the pre-auth is set to the auth
// user, then no further checking is necessary.
$validating_id = logintoboggan_validating_id();
$pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID;
if ($pre_auth) {
// Check to see if an admin has manually removed the pre-auth role from
// the user. If so, send the account activation email.
// The logic here is a bit funky, but necessary because we have no way
// of knowing if a missing $edit['roles'][$validating_id] is because
// the pre-auth role was disabled on this page save or a previous save.
// So, we calculate a removal of the pre-auth role manually as follows:
// 1. The pre-auth role exists in the user's current roles.
// 2. There's an available $edit['roles'] array to examine.
// 3. The pre-auth role is not in the array.
if (array_key_exists($validating_id, $user_edit->roles) && isset($edit['roles']) && (!isset($edit['roles'][$validating_id]) || !$edit['roles'][$validating_id])) {
// Mail the user, letting them know their account now has auth user perms.
_user_mail_notify('status_activated', $user_edit);
}
}
}
}
}