$username))); @pg_free_result($rs); @pg_close($db); return false; } $mail = ''; if (@pg_fetch_result($rs, 0, 'success') == "1") { $mail = @pg_fetch_result($rs, 0, 'email'); } else { watchdog('user', t('Community login failed for user %user.', array('%user' => $username))); @pg_free_result($rs); @pg_close($db); return false; } @pg_close($db); // Login successful. See if we need to store a copy of user info in drupal db $u = user_load(array('name' => $username)); if (!isset($u->uid)) { // User not present in drupal - save stub. Set password to something very random. $u = user_save('', array ( 'name' => $username, 'pass' => user_password(42), 'mail' => $mail, 'init' => $mail, // not sure why, but ldap does it so... 'status' => 1)); watchdog('user', t('Added record for community user %user', array('%user' => $username))); } else { // User is present, check if email has changed if ($u->mail != $mail) { $old = $u->mail; user_save($u, array( 'mail' => $mail)); watchdog('user', t('User %user changed email from %old to %new', array('%user' => $username, '%old' => $old, '%new' => $mail))); } } return true; } /* * Get rid of the send-me-a-password link. */ function pglogin_form_alter($form_id, &$form) { if ($form_id == 'user_login_block') { unset($form['links']); } }