There should be an interface where we can configure the username structure. As per the current module, we can do so by writing code inside hook_email_registration_name($edit, $account)

Interface feature can be added as a patch to the current module, or it can be done in a separate module. I guess we should this as a patch (as a new feature). It would be good if we add token support in the interface.

Comments

subhojit777’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Assigned: Unassigned » subhojit777
Status: Active » Needs review
StatusFileSize
new4.08 KB

Hello, here is the patch that provides an UI to configure username pattern. If hook for constructing username not found, then this patch checks if setting exists for username pattern, and constructs username as per setting. I guess this will be as an added feature in this module, because users would like to provide username patterns in UI rather than writing code.

greggles’s picture

This looks decent to me. Any chance you can write a test?

subhojit777’s picture

Sure. I have not written tests before. I saw that there is a email_registration.test inside the module, shall I include my test case inside that, and submit that as patch?

greggles’s picture

Yes, that would be great, thanks.

If you prefer to submit it as a behat test that would be fine too (I find those easier to write - especially when leveraging the Drupal extension).

subhojit777’s picture

StatusFileSize
new5.31 KB

Hello greggles,

Here is a patch with test case included. The test does: create a new user, then check whether the username matches a defined username pattern. I guess the test should check this. Have I missed anything else? I found writing tests using simpletest easy, so did not wrote tests in behat test.

Also I found that one of your test is failing "By default, username can log in.". And also the assertion messages are enclosed within t(), even though we should not do that https://drupal.org/node/265828. I guess the corrections should be done in another issue. I can help in this case if I get time :)

System Lord’s picture

I would like to jump in here and offer any testing I can. I've been looking for something like this. I never liked any part of my user's email address exposed. No matter how much information i provided my users that they should change their username less than 1% ever did. Now, with this I can simply make it default to: User_1234. Very nice! This is so important to me that I'm already using this on my live site.

So....

I've installed this and made the pattern: User
I'm using D731

So far "User_1234" seems to be showing up everywhere it should...display name, privatemsg, comments, content author, and emails. It doesn't seem to be changing existing usernames, which is good.

I'm a little concerned with your (subhojit's) comment...

Also I found that one of your test is failing "By default, username can log in.". And also the assertion messages are enclosed within t(), even though we should not do that https://drupal.org/node/265828. I guess the corrections should be done in another issue. I can help in this case if I get time :)

I really don't know enough about coding/patching to help with that, and I haven't experienced any conflicts yet, but I would like to see this patch finalized and committed. I'm prepared to help in anyway I can...test and such.

Thank you for this patch!!!!

Mark

subhojit777’s picture

@Mark the reason you are not seeing user id in the username, because username is set before the user is created, and at that moment the user object does not have the user id.

You could set something else, for example use first name and last name combination as pattern to set username.

Or you can do this, use rules to alter username to user_[user_id] after user is created.

I would prefer the first approach :)

System Lord’s picture

I do not collect names of users, so "User_????" is perfect. When I say "User" I mean actually using the word "User" as the the actual set pattern not as a token. My concern (before this patch) was that this module (I think its this module) would append the first part of the user's registered email address to "_[UID]" making it "[email]_[UID]". And now I don't have to worry about that :)

My other concern (after the patch) is your comment

Also I found that one of your test is failing "By default, username can log in.". And also the assertion messages are enclosed within t(), even though we should not do that https://drupal.org/node/265828. I guess the corrections should be done in another issue. I can help in this case if I get time :)

I'm not sure what you mean. I've done testing and my user's cannot login with their username, which is the way I like it and they way i have it set in admin/config/people/accounts.

The bottom line for me is that I like this patch and wouldn't change a thing.

System Lord’s picture

StatusFileSize
new22.77 KB
subhojit777’s picture

I am telling about simpletests. We write simpletests to check whether features if certain module is working or not.

And as I gave here in this link, https://drupal.org/node/265828 we should not use t() functions to enclose assertion texts.

Thats what I said in comment #5

The last submitted patch, 1: configure_username_ui-2273265-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: configure_username_test-2273265-5.patch, failed testing.

The last submitted patch, 5: configure_username_test-2273265-5.patch, failed testing.

subhojit777’s picture

Status: Needs work » Needs review
StatusFileSize
new5.51 KB
andypost’s picture

Issue tags: +needs forward port to Drupal 8

LGTM, would be great to have screenshots

+++ b/email_registration.module
@@ -155,7 +166,7 @@ function email_registration_form_user_login_block_alter(&$form, &$form_state) {
-}
+  }

just nitpick

bluegeek9’s picture

Assigned: subhojit777 » Unassigned
Status: Needs review » Closed (outdated)
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:

Drupal 7 is End of Life. We recommend upgrading to a supported version of Drupal.