=== modified file 'webserver_auth.module'
--- webserver_auth.module	2008-08-07 15:23:48 +0000
+++ webserver_auth.module	2008-08-07 15:31:46 +0000
@@ -1,6 +1,9 @@
 <?php
-// $Id: webserver_auth.module,v 1.22 2008/07/17 20:37:37 weitzman Exp $
+// $Id$
 
+/**
+ * Implementation of hook_menu().
+ */
 function webserver_auth_menu() {
   $items = array();
   $items['admin/settings/webserver_auth'] = array(
@@ -13,6 +16,9 @@
   return $items;
 }
 
+/**
+ * Implementation of hook_init().
+ */
 function webserver_auth_init() {
   global $user;
 
@@ -57,30 +63,27 @@
  * Implementation of hook_user().
  */
 function webserver_auth_user($op, &$edit, &$account, $category = NULL) {
-  if ($op == 'submit' && $category = 'account') {
-    // Only fiddle with new accounts.
-    if (empty($account->uid)) {
-      $account->name = trim($account->name);
-      // Pretty up the username for NTLM authentication (i.e. Windows)
-      if (variable_get('webserver_auth_strip_prefix', TRUE)) {
-        // Get 'bar' from 'foo1\foo2\bar'
-        $account->name = array_pop(explode("\\", $account->name));
-      }
-      if (variable_get('webserver_auth_strip_domain', TRUE)) {
-        // Get 'foo' from 'foo@bar'
-        $account->name = array_shift(explode('@', $account->name));
-      }
-
-      // Generate an e-mail address automagically
-      if ($domain = variable_get('webserver_auth_email_domain', '')) {
-        if ($account->name) {
-          $account->mail = $account->name. '@'. $domain;
-        }
-      }
-      // run some custom code to modify the user object at creation time
-      if ($code = variable_get('webserver_auth_insert', '')) {
-        eval('?>'. $code);
-      }
+  if ($op == 'insert' && $category = 'account') {
+    $account->name = trim($account->name);
+    // Pretty up the username for NTLM authentication (i.e. Windows)
+    if (variable_get('webserver_auth_strip_prefix', TRUE)) {
+      // Get 'bar' from 'foo1\foo2\bar'
+      $account->name = array_pop(explode("\\", $account->name));
+    }
+    if (variable_get('webserver_auth_strip_domain', TRUE)) {
+      // Get 'foo' from 'foo@bar'
+      $account->name = array_shift(explode('@', $account->name));
+    }
+    db_query("UPDATE {users} SET name = '%s' WHERE uid = %d", $account->name, $account->uid);
+    // Generate an e-mail address automagically
+    if ($domain = variable_get('webserver_auth_email_domain', '')) {
+      if ($account->name) {
+        db_query("UPDATE {users} SET mail = '%s@%s' WHERE uid = %d", $account->name, $domain, $account->uid);
+      }
+    }
+    // run some custom code to modify the user object at creation time
+    if ($code = variable_get('webserver_auth_insert', '')) {
+      eval('?>'. $code);
     }
   }
   elseif ($op == 'logout') {
@@ -90,6 +93,9 @@
   }
 }
 
+/**
+ * Implementation of hook_settings().
+ */
 function webserver_auth_settings() {
   $form['webserver_auth_email_domain'] = array(
     '#type' => 'textfield',
@@ -120,8 +126,8 @@
       '#type' => 'textarea',
       '#title' => 'User account modification',
       '#default_value' => variable_get('webserver_auth_insert', ''),
-      '#description' => t("Modify user accounts at the time of creation. Use PHP code (enclosed in <code>&lt;?php</code> and <code>?&gt;</code>). The variable <code>\$account</code> is available as in <a href=\"http://api.drupal.org/api/function/hook_user/6\">hook_user('submit',...)</a>. Changes to the \$account object will be automatically saved."),
+      '#description' => t("Modify user accounts at the time of creation. Use PHP code (enclosed in <code>&lt;?php</code> and <code>?&gt;</code>). The variable <code>\$account</code> is available as in <a href=\"http://api.drupal.org/api/function/hook_user/6\">hook_user('insert',...)</a>. Changes to the user object must be explicitly saved to the database to be made permanent."),
     ),
   );
   return system_settings_form($form);
-}
\ No newline at end of file
+}

