Index: openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl,v
diff -u -r1.42 -r1.43
--- openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl	24 Sep 2003 17:30:59 -0000	1.42
+++ openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl	25 Sep 2003 11:37:32 -0000	1.43
@@ -807,6 +807,42 @@
         }
     }
     
+    # Default a local account username
+    if { $user_info(authority_id) == [auth::authority::local] \
+             && [auth::UseEmailForLoginP] \
+             && [empty_string_p $username] } {
+
+        # Generate a username that's guaranteed to be unique
+        # Rather much work, but that's the best I could think of
+
+        # Default to email
+        set username [string tolower $user_info(email)]
+
+        # Check if it already exists
+        set existing_user_id [acs_user::get_by_username -authority_id $authority_id -username $username]
+
+        # If so, add -2 or -3 or ... to make it unique
+        if { ![empty_string_p $existing_user_id] } {
+            set match "$user_info)username)-%"
+            set existing_usernames [db_list select_existing_usernames { 
+                select username 
+                from   users
+                where  authority_id = :authority_id
+                and    username like :match
+            }]
+
+            set number 2
+            foreach existing_username $existing_usernames {
+                if { [regexp "^${username}-(\\d+)\$" $existing_username match existing_number] } {
+                    # matches the foo-123 pattern
+                    if { $existing_number >= $number } { set number [expr $existing_number + 1] }
+                }
+            }
+            set username "$username-$number"
+            ns_log Notice "User's email was already used as someone else's username, setting username to $username"
+        }
+    }
+
     set error_p 0
     with_catch errmsg {
         # We create the user without a password
Index: openacs-4/packages/acs-bootstrap-installer/tcl/10-utilities-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-bootstrap-installer/tcl/10-utilities-procs.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/acs-bootstrap-installer/tcl/10-utilities-procs.tcl	25 Sep 2003 10:32:19 -0000	1.6
+++ openacs-4/packages/acs-bootstrap-installer/tcl/10-utilities-procs.tcl	25 Sep 2003 11:37:32 -0000	1.7
@@ -64,24 +64,3 @@
     }
     return $files
 }
-
-namespace eval auth {}
-namespace eval auth::authority {}
-
-ad_proc -public auth::authority::local {} {
-    Returns the authority_id of the local authority.
-} {
-    # LARS: This is a simply implemtation which we need for creating an administrator
-    # during bootstrap install.
-    # Even though bootstrap-installer loads the acs-authentication/tcl/authenticaion-procs.tcl, 
-    # where this is defined, it might get loaded in a different interpreter from the
-    # one serving the create-administrator-2 page.
-    return [db_string local_auth { select authority_id from auth_authorities where short_name = 'local' }]
-}
-
-ad_proc -public auth::UseEmailForLoginP {} {
-    Do we use email address for login? code wrapped in a catch, so the 
-    proc will not break regardless of what the parameter value is.
-} {
-    return 0
-}
Index: openacs-4/packages/acs-tcl/tcl/community-core-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/community-core-procs.tcl,v
diff -u -r1.31 -r1.32
--- openacs-4/packages/acs-tcl/tcl/community-core-procs.tcl	24 Sep 2003 17:30:29 -0000	1.31
+++ openacs-4/packages/acs-tcl/tcl/community-core-procs.tcl	25 Sep 2003 11:37:32 -0000	1.32
@@ -104,37 +104,6 @@
         set url [db_null]
     }
 
-    if { [empty_string_p $authority_id] } {
-        set authority_id [auth::authority::local]
-    }
-
-    # Lars: This is a hack until we sort out the UsernameIsEmail situation
-    if { [auth::UseEmailForLoginP] && [empty_string_p $username] } {
-        # Generate a username that's guaranteed to be unique
-        # Rather much work, but that's the best I could think of
-
-        set username [string tolower $email]
-        set existing_user_id [acs_user::get_by_username -authority_id $authority_id -username $username]
-        if { ![empty_string_p $existing_user_id] } {
-            set match "$username-%"
-            set existing_usernames [db_list select_existing_usernames { 
-                select username 
-                from   users
-                where  authority_id = :authority_id
-                and    username like :match
-            }]
-            set number 2
-            foreach existing_username $existing_usernames {
-                if { [regexp "^${username}-(\\d+)\$" $url match n] } {
-                    # matches the foo-123 pattern
-                    if { $n >= $number } { set number [expr $n + 1] }
-                }
-            }
-            set username "$username-$number"
-            ns_log Notice "User's email was already used as someone else's username, setting username to $username"
-        }
-    }
-
     set creation_user ""
     set peeraddr ""