I developed a module to do this same thing before stumbling upon it here, and I took a slightly different approach. I've rolled a patch to incorporate these changes into the 5.x-1.x-dev version of this module. The changes are:

1) Instead of manipulating the database directly in hook_user() for the insert and update cases, I just feed in the new username into the form on validate. This allows greater inter-operability in the workflow with other modules.
2) If the username is set to be equal to the email address per the flag on the admin page, then when users are allowed to edit their own username they should not see a separate username field. I check for this in hook_form_alter() in the user_edit case, which breaks immediately if the flag is false but carries through to user_register case if the flag is true.
3) And finally, I need the super-admin to always keep the same username, so I just put in a quick check for that. Perhaps that can be made more customizable in the future, if you want the admin's username to remain the same as well?

Hope this helps. Please review the patch, and hopefully we can get it into the next release!

Comments

bomarmonk’s picture

I am testing your patch. Is this fix needed for your update as well: http://drupal.org/node/345399 ?

bomarmonk’s picture

Your approach seems to work. Although existing user edit pages do not hide the user name field. This may be by design, but should this be configurable in the module's setting's page? I'll report back if I discover anything else that might be helpful for discussion. Thanks again for your work on this.

sbandyopadhyay’s picture

I believe that the user name field should be hidden only if the username = email (per the setting on the module's settings page). After all, if you have email = username, then why bother having two separate fields that show the same exact thing?

Please let me know if we should had that in as an adjustable option however.

sbandyopadhyay’s picture

By the way, bomarmonk-- if you're checking as the super admin (uid=1) then you will see the username in the edit page by design. (I like keeping my username "admin" instead of "admin@example.com".)

bomarmonk’s picture

Got it-- I think that's what I was seeing! I should have thought through that possibility! Thanks for the very nice work on this module!

sbandyopadhyay’s picture

Status: Needs work » Needs review
StatusFileSize
new3.16 KB

Been using this now on my production site and it's working without any problems-- except one. I mistakenly didn't port a couple important lines from my older version of the module, and so it would change the admin's username to a random series of letters every time the I updated my admin profile. That causes a few problems, to say the least-- but no matter. It's fixed now with this patch.

Hopefully we can get an updated release of this module soon? I'll try to compile this and all other changes into one issue later tonight.

update- this patch is re-rolled against the original 5.x-dev version, so disregard the patch above.

sbandyopadhyay’s picture

I have folded this patch into a master patch to the 5.x-1.x-dev version for easy updating on several issues: #366504: Master patch combining several recent issues.

Christopher Herberte’s picture

Status: Needs review » Closed (fixed)

patch applied to head