Optionally update user names when a user is edited

sethcohn - November 6, 2008 - 14:58
Project:Email Registration
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

If a user changes email addresses, right now, the behavior is that their username remains the old email (or some form of it).
That's broken behavior IMHO, since it's extremely confusing to update your email, but be told your 'username' hasn't changed.

A simple addition to the code would be:

<?php
function email_registration_user($op, &$edit, &$account, $category = NULL) {
  switch (
$op) {
    case
'update':
    case
'insert':
?>

to follow thru on the update of the user info. If desired, a check for access permission to "change username" could happen (if false, break), but I suspect that's likely overkill if you are using email_registration in the first place.

#1

Chris Herberte - November 28, 2008 - 00:03
Status:needs review» fixed

Cool, i have no problem with this. I've committed it to 5.x-1.x-dev / HEAD please test.

#2

danielb - December 2, 2008 - 03:56

I am concerned about this - one of the good points about this module is that it only effects new user accounts, and will not destroy the existing usernames. A username being magically changed because an account is saved and then the account being rendered inaccessible because of this is certainly not desirable.
This should be a configurable option.

#3

danielb - December 2, 2008 - 03:58
Status:fixed» active

#4

danielb - December 2, 2008 - 04:01

To explain - I make a new Drupal site almost everyday. I have a button that I press which checks out the latest code, and a copy of a half-made drupal database, complete with usernames for User 1, for the developer, for the SEO strategist, and for the webmaster that will be using the website.

If any of these usernames were to change just because user_save is called to modify some value on the account (and this doesnt' necessarily happen in the user.module - any module can do this) you will destroy the ability to login to this account.

Yes I know you could look in the database for the email that exists on those accounts, but I am not going to tell the old lady who relies on these logins that this is now what she must do, after 2 years of teaching her to do it one way...

#5

Chris Herberte - December 2, 2008 - 04:06

dainielb, your comments a most certainly valid. This should be optional.

#6

sethcohn - December 2, 2008 - 14:38

I agree, for sites with existing (non-emailed) user names grandfathered in, this would be disruptive. Perhaps only if the username is already an email address, change it to the new one?
That would allow seamless functioning for both old names, but still allow newer users with email addressed usernames to not be stuck with an obsolete username based on an old email address they no longer use.

#7

danielb - December 2, 2008 - 22:49
Category:bug report» feature request

I know you don't have a configuration screen for this module at this point, but there were some other ideas I had before I saw this thread about things that could be configurable (like whether to use the whole email, or just the first part of the email [which needs the index numbering to avoid duplicates]) - so in the long run I think it may be worth having a config screen. Or at least altering the "user settings" form to add your own choices and submit handler, that would be fine too.

#8

greggles - June 9, 2009 - 00:28
Title:Only on insert? Should be called on update as well...» Optionally update user names when a user is edited

Slightly better title.

#9

greggles - June 9, 2009 - 00:37

Another potential solution to this problem is presented in #384506: settings for which roles we want to change the user name with the idea that the username would only be changed during edit for certain roles. That way admin accounts stay the same, other accounts still change. I think this idea is slightly better so marking that as a duplicate of this.

#10

Alex Lawrence - October 8, 2009 - 16:36

Hi,

I modified the module in order to get functionality mentioned here. Needed synced usernames, so I implemented the suggestion with the role to specify. Note that the role may not have the permission to change own usernames in order for the module to work.

Additionally I implemented a basic setting for the name generation so usernames can also be the full e-mails. I know there is a hook for the name generation but I don´t want to write an extra module just for this behavior.

Maybe this helps. Would be great to see the sync feature in upcoming releases.

Cheers

Note: It is just the .module file.

AttachmentSize
email_registration-modified.zip 2.25 KB
 
 

Drupal is a registered trademark of Dries Buytaert.