You are here

function ldapauth_user in LDAP integration 6

Same name and namespace in other branches
  1. 5.2 ldapauth.module \ldapauth_user()
  2. 5 ldapauth.module \ldapauth_user()

Implements hook_user().

File

./ldapauth.module, line 193
ldapauth provides authentication against ldap server.

Code

function ldapauth_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'validate':
      if (isset($account->ldap_authentified) && LDAPAUTH_ALTER_EMAIL_FIELD == LDAPAUTH_EMAIL_FIELD_REMOVE || LDAPAUTH_ALTER_EMAIL_FIELD == LDAPAUTH_EMAIL_FIELD_DISABLE) {
        unset($edit['mail']);
      }
      break;
    case 'update':

      // Handle password mods after ldapdata does update in submit
      if ($category == 'account') {

        // If authentication is being done in "LDAP only" mode, passwords
        // should not be written to the database, or users would be able
        // to log in even after removing their LDAP entry.
        if (isset($account->ldap_authentified) && (LDAPAUTH_LOGIN_PROCESS == LDAPAUTH_AUTH_EXCLUSIVED || !LDAPAUTH_SYNC_PASSWORDS)) {
          $edit['pass'] = NULL;
        }
      }
      break;
    case 'view':
      $category_title = t('LDAP authentication');
      if (user_access('administer users') && isset($account->ldap_authentified) && $account->ldap_dn) {
        $server = ldapauth_server_load($account->ldap_config);
        $account->content[$category_title] = array(
          '#type' => 'user_profile_category',
          '#title' => $category_title,
          '#attributes' => array(
            'class' => 'ldapauth-entry',
          ),
          '#weight' => LDAPAUTH_PROFILE_WEIGHT,
          'ldap_to_local' => array(
            '#type' => 'user_profile_item',
            '#title' => t('Convert User'),
            '#value' => l(t('Convert from LDAP user to local Drupal user'), 'admin/settings/ldap/ldapauth/user/' . $account->uid . '/tolocal'),
            '#weight' => -1,
          ),
          'ldap_server' => array(
            '#type' => 'user_profile_item',
            '#title' => t('LDAP server'),
            '#value' => l($server->name, 'admin/settings/ldap/ldapauth/edit/' . $server->sid),
            '#weight' => 0,
          ),
          'ldap_dn' => array(
            '#type' => 'user_profile_item',
            '#title' => t('LDAP dn'),
            '#value' => $account->ldap_dn,
            '#weight' => 1,
          ),
        );
        if (!empty($server->puid_attr)) {
          $user_info = ldapauth_userinfo_load_by_uid($account->uid);
          $puid = $user_info ? $user_info->puid : t("PUID MISSING!!!!");
          $account->content[$category_title]['ldap_puid'] = array(
            '#type' => 'user_profile_item',
            '#title' => t('LDAP PUID'),
            '#value' => $puid,
            '#weight' => 3,
          );
        }
      }
      break;
    case 'delete':
      $user_info = ldapauth_userinfo_load_by_uid($account->uid);
      ldapauth_userinfo_delete($user_info);
      db_query("DELETE FROM {authmap} WHERE uid = %d AND module = 'ldapauth'", $account->uid);
      break;
  }
}