You are here

function logintoboggan_user in LoginToboggan 5

Same name and namespace in other branches
  1. 6 logintoboggan.module \logintoboggan_user()

Implementation of hook_user().

File

./logintoboggan.module, line 969
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('login_successful', 0)) {
    drupal_set_message(t('Login successful.'));
  }
  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('login_with_mail', 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.'));
      }
    }
  }
}