Automatically generate a username from realname fields.

noahb - April 14, 2009 - 09:46
Project:RealName
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Attached is a small module that 1) hides the username field, and 2) generates a username from the realname fields that have been selected. I've tested this with content_profile, but not core profile.

AttachmentSize
realname_generate.patch6.45 KB
realname_generate.zip2.51 KB

#1

design.er - April 18, 2009 - 13:41

Hi,

I installed and tested this module.
Unfortunately, after clicking the register button on the registration form I always get a white screen either using a . (dot), - (dash), whitespace or   as separators for the username generation.
If using whitespace or nothing as separator then field validation seems to be deactivated -> if some required fields are empty and I click on the register button i receive the white screen.
If I use dot and dash as separators then validation works fine but after filling the registration form out and clicking the register button I also get a white screen.

It would be sooo great if this nice module would work soon.
I'd like to continue the testing and reporting if you will publish updates. :)

Thanks a lot for you work and passion!

Regards,
Stefan

#2

NancyDru - April 18, 2009 - 14:22
Status:needs review» needs work

@noahb: 1) I'm not sure I understand what makes this better than what exists now. 2) We stopped using the "separator" in RealName long ago and use a pattern, which allows for "Mr. Samuel A. Jones, III" (note mixed separators).

#3

noahb - April 18, 2009 - 17:37

@NancyDru The main purpose of this module is to automatically generate a username when a new user is registering. It simply removes the username field from the registration form, and uses a composite of the realname fields to 'generate' the username. Does this make sense?

@design.er Thanks for testing this out. I had not done very extensive testing so I'm sure you've found a bug.. I'll try to past a fix in the coming days.

#4

design.er - April 24, 2009 - 12:41

Noah, did you had any time to get closer to a working release yet?
It would be awesome to implement this module into my current project - would be a kind of life-saver. :)

Best regards,
Stefan

#5

noahb - April 24, 2009 - 20:32
Status:needs work» needs review

Hi Stefan,

I made some changes this morning, but I wan't able to recreate the problems you've mentioned. It sounds like I might have some whitespace or line break issues in my source files, but I couldn't find anything... Can you try to test this newly attached version to see if you still get the same errors?

cheers,

Noah

AttachmentSize
realname_generate.zip 2.76 KB
realname_generate.patch 7.51 KB

#6

design.er - April 24, 2009 - 21:09

Hi Noah,

The registration process works absolutely fine for me now! :)
I just found one bug. After registering: if you try to change something in your profile (i.e. user/1/edit) and click on the save button, the system wants you to enter a username.
I think this is the last thing that should be done.
We are definitively on the right course! :)

Again thanks a lot for your great work, Noah! :)

Rock on!
Stefan

#7

design.er - April 24, 2009 - 21:51

Ok, now I know why and when this bug appears - I'm thinking about a carrier as professional software tester. :P *kidding*
If you update the profile as account owner (and don't have the permission to change your username), everything seems to be ok.
If you update the account as somebody who has permissions to manage users you are able to see the username field and then the system wants you to enter a username because this field is empty.
From this moment on the system wants you to enter a username everytime, either you can see this field or not.

Would be nice if there is a way to prevent that.

Regards,
Stefan

#8

noahb - April 24, 2009 - 23:53

Stefan,

Thanks for testing this out... I know exactly what you mean and I spent some time trying to think of the best solution, but wasn't sure which direction to take. I guess the best solution would be to do what you say and just removed the username field from all the forms. The reason I left it for admin users is that I thought they might want to be able to add a user without entering all the profile data, and then there would HAVE to be some way to enter a username since the other profile fields would not be available to generate the username from...

I think for now though I will just do as you suggest and hide the username field, and then if this module ever gets any uptake we can think about adding a switch to show/hide the username from the various forms.

your thoughts?

#9

design.er - April 25, 2009 - 00:07

sounds great. I'm looking forward to test your next release. :)

#10

noahb - April 25, 2009 - 00:28

Try changing the realname.module file as follows and check the result.

<?php
     
case 'user_profile_form':
/*
*      @TODO Decide how to hanle the user edit form  
*      if (user_access('administer users')) {
*        break;
*      }
* /
        if (isset($form['account'])) {
          $form['account']['name']['#type'] = 'hidden';
          $form['account']['name']['#required'] = FALSE;
        }
        else{
          //I'm not sure if this case ever comes up, but just in case...
          $form['name']['#type'] = 'hidden';
          $form['name']['#required'] = FALSE;
        }
        break;
?>

Are you using content_profile or core profile module to test this?

AttachmentSize
realname_generate.patch 7.58 KB

#11

design.er - April 25, 2009 - 08:46

I use both modules. core profile for birthday & user registration notification and content_profile for cck, content_taxonomy etc.

I patched the zipped files (from comment #5; patching was successfully) and when installing the patched files I instantly get a WSOD through the whole site.
When removing the patched files from modules folder everything works fine again.

Hey, thank you for your passion! :)

#12

design.er - April 25, 2009 - 17:01

Hmm... stupid question: Did you mean that I should try to change the code in the realname.module?
I found your snippet in the realname_register.module so I thought that this is the point of change of your current patch that should make it work the way we discussed yesterday.
So if this is the point I was missing in the process maybe that could explain my WSOD?

Please help me to bang through my walls of stupidity. :)

Cheers,
Stefan

#13

noahb - April 25, 2009 - 22:40

Hey Stefan,

Yeah, you can just go ahead and try to comment out that one section of the realname.module.. The part I showed commented out in #10 that starts with the "@TODO".

I'll try to post a a better fix for you soon.

#14

design.er - April 25, 2009 - 23:53

I hope you meant not the realname.module but realname_generate.module - I only found here the mentioned lines.
I commented the lines out and got suddenly a WSOD again. :(

The next strange thing is that since I patched the files from #5 with the patch from #10, I get the WSOD when clicking on the submit button in the registration again, although I uninstalled the module completely and reinstalled the good files from #5. I hope this is browser caching or something similar. I will try it on Monday again. After 16 hours office I'm basta.

We'll get it! ...we're on the right way ...I feel it! *magically* :D

#15

design.er - April 29, 2009 - 09:34

Hi Noah, I hope you've got a great weekend. :)
Any news regarding the realname_generate.module?
It would be really great if we'll get this baby running soon.

Blessings! :)

Stefan

#16

espirates - May 3, 2009 - 03:56

I get this error when clicking create new account

Fatal error: Cannot use string offset as an array in /drupal/sites/all/modules/realname_generate/realname_generate.module on line 90

#17

intent - May 4, 2009 - 13:50

Sounds like a great idea. Subscribing.

#18

artis - May 8, 2009 - 03:53

If you are getting the error that you need to enter a username when attempting to edit a user account (user/*/edit) then...

Goto: /admin/user/realname/bypass
Add this line in the "Bypass these forms:" box

user_profile_form name

Now the hidden username field will be populated with the username from the database. With the username field hidden on user/*/edit the only way to change the username in the is by changing the fields that build your realname, which is the way it should work in my opinion.

#19

noahb - May 9, 2009 - 10:32

Hopefully the attached version will fix some of the WSOD issues.

I've been thinking about the implications of generating a username, and how to update/change the generated name if/when any of the fields that are being used to generate the username are changed. So far, I can't think of a clean way to keep them synchronized.
Somehow we need to know when a user's content profile is being updated, and if so, regenerate the username, but the question is how...

Beyond that issue, there is also the problem of how a user is supposed to know their username when they want to log in. With other modules installed, you can log in using your email, but it's less than ideal (from a UX perspective) that we're magically generating a username...

AttachmentSize
realname_generate.zip 2.79 KB

#20

design.er - May 9, 2009 - 11:06

Hmm... you're absolutely right with your doubts.
I see two ways to improve the UX perspective...
1. After creations and updates of the username there may appear a message with the new generated username and that this should be used for log-ins in future. But indeed this is not the best solution - the most users will forget the username.

2. I think this is beyond the possibilities of this sub-module but maybe it's possible with the realname module yet: The user has the possibility to log-in with the realname. So the value of the username would become less important. But then there should be a notice about that possibility in the log-in block - i.e. replace the string "Username" with "Real name" or the labels of the fields that are used for the realname module (i.e. "firstname lastname") or something else.

Is it possible to use/alter the trigger module or cron to notify about user's content profile updates? I'm not a coder so this suggestions are maybe really stupid. If so, please forgive me. :)

Thanks for the new release. I will test the it (hopefully) today and give feedback.

#21

noahb - May 9, 2009 - 11:20

With regards to logging in, I think the cleanest (and maybe only) solution is to require users to login using their email address, and just try to remove the whole concept of a username from the end users perspective. I'm not sure how easy/effective this would be, but at least it seems to be inline with the motivations of using this module in the first place. Both facebook and linkedin use an email for login, so that is a tested and popular solution. The question then becomes how to remove the concept of usernames as much as possible?

As for the other issue, about updating a username upon changes to the underlying realname fields, well, this becomes a mute point if the concept of username is stripped out completely, right? There would be no need to update or regenerate a username if the user never needs to use their username... That said, there is probably some way to regenerate the username, I just haven't thought too much about it yet.

#22

NancyDru - May 13, 2009 - 01:39

Logging in with email can be done with Login Toboggan.

As for commenting that code, should we change the "Bypass" default to include "user_profile_form name?"

#23

noahb - May 13, 2009 - 14:23

Yeah, I've been using Login Toboggan all along with my setup and I have use the String Overrides module to remove all "username" references from the login and password retrieval forms. I suppose I could just build those changes into a form_alter, and make Login Toboggan a required dependency as well...

#24

artis - May 21, 2009 - 18:06

I also use RealNames with Login Toboggan and String Overrides to get rid of the concept of a username on my site. However, the one area where I haven't been able to use realnames overriding the username is when using a userreference cck field. I'd hoped with the realname dev being able to override the username on views that I would be able to use a view filter and display a list of realnames instead of usernames, but that hasn't worked. The realname_generate module works, although it is problematic since usernames must be unique and if you aren't using email login then the user wont' know what their username is.

If I could find a solution for displaying realnames on a userreference cck field then I wouldn't need the realname_generate module at all and the site would run much more smoothly.

#25

artis - May 21, 2009 - 19:02

Found my answer here: http://drupal.org/node/380460
So I don't need realname_generate anymore.

UPDATE: Ends up that I don't even need that module either. If I use a view-filter on the userreference cck field I can actually override the username and use the realname. Anyone needs help with this let me know.

#26

kevin riggen - July 29, 2009 - 00:00

subscribing. Cool module.

#27

noahb - October 4, 2009 - 00:38

I've updated this module a bit... Once again, the purpose of this is to i) hide the username field on the registration field, and ii) automatically generate a username based on the RealName fields that have been defined. It's tested with content profile, and should work with profile too, but I haven't tested yet.

AttachmentSize
realname_generate.zip 4.39 KB

#28

espirates - October 4, 2009 - 07:13

I get this error message from #27

Fatal error: Cannot use string offset as an array in /sites/all/modules/realname_generate/realname_generate.module on line 104

#29

noahb - October 4, 2009 - 19:43

@espirates...
I looked at this today, and couldn't figure out why your getting this error. Which versions of cck, content_profile, and realname are your using?

Here's another new version that will probably only work with the latest -dev release of realname...

AttachmentSize
realname_generate.zip 5.81 KB

#30

espirates - October 5, 2009 - 03:57

Here are the versions being used

realname 6.x-1.2
cck 6.x-3.x-
contentprofile 6.x-1.0-

I received error message using both core profile and contentprofile, will try this new zip.

Update This new zip works, also in the add user section no username input field appears until after you add and click save. Not sure if this is by design or not, it works, thanks.

#31

NancyDru - October 5, 2009 - 05:56

@noahb: I appreciate the effort, but understand that we cannot work with a zip file, or any other form of complete module replacement. We need a real patch.

#32

NancyDru - October 5, 2009 - 05:56
Status:needs review» needs work

#33

design.er - October 5, 2009 - 12:19

Hi Noah,

thank you very much for your work. I tested the latest release (#29) with the core profile module on a fresh Drupal installation and it works great for me.

Regards,
Stefan

#34

noahb - October 5, 2009 - 12:56

@NancyDru: Of course I understand, but I figured that it would be more testing with the zip... Anyway, here's the patch. I put the module into a sub-folder called 'contrib' but if you have a different preference, let me know and I can make a new patch. Lastly, feel free to make any changes you think are necessary/important, or let me know, and I can try to do this.

Also, I started to create some tests for this, but they're not working yet, as I've yet to figure out how to do somethings with SimpleTest.

@espirates: Thanks for your continued testing... As you saw/mentioned, when enabled I decided to hid the username field from the admin create user form. This was not how I really wanted to do it, but I was having trouble with validation if I kept it there and empty. The other alternative was to leave it there and pre-fill it with some random text, that's I'd change in validation, but that also seemed less than optimal... In the end, I decided to hide it and leave the message that the username was being automatically generated. Finally, as you saw in the user edit page, the choice to auto generate is controlled by a checkbox (similar to how pathauto works on node forms), but only for those that have the ability to change their own username.

@ALL: There might still be some bugs, and definitely there are some optimizations/features to add (any suggestions?). Finally, much of the inspiration (and some code) came from the http://drupal.org/project/auto_username project, which didn't have a 6.x version, and also didn't work with RealName... I'd like to hear others thoughts about whether I should try to fold some of this new code back into that project, or whether the differences justify a new release.

AttachmentSize
realname_generate.patch 21.87 KB

#35

noahb - October 5, 2009 - 12:58
Status:needs work» needs review

ahem

#36

kevin riggen - October 5, 2009 - 18:49

: )
thanks noahb

#37

compuguru - October 6, 2009 - 23:43

subscribing...may try and test it if I get a chance

#38

netsurfer20 - October 16, 2009 - 00:09

I am wondering since the realname module requires a security update, is this new function in the latest update, what should we do ?

#39

espirates - October 20, 2009 - 20:49

I'm getting some weird behavior from this lately. When a new user creates an account for admin approval, an admin message will say this name already exists yet the name it gives is an entirely different name. It won't let you approve it but if you go into users list, the new account is created. Anyone else experience this?

#40

noahb - October 20, 2009 - 22:58

your right... there was a bug in there.

try this patch.

AttachmentSize
realname_generate_2.patch 22.12 KB

#41

espirates - October 20, 2009 - 23:46

Any chance you could include the zip files, patches are alien for non-programmers :)

#42

noahb - October 21, 2009 - 05:16

you can try this one...
Grab the zip from the next comment instead.

AttachmentSize
realname_generate.zip 10.4 KB

#43

noahb - October 22, 2009 - 19:55

This one doesn't contain some extraneous files.

Edited (to add): Don't use this one, unless you want to confuse people.

AttachmentSize
realname_generate.zip 5.94 KB

#44

espirates - October 22, 2009 - 19:57

This module is really causing havoc, its renaming usernames with other active usernames. The correct email remains but the username gets changed to the previous new user's name. I think it would be good if it did not allow duplicate names, currently it's giving each new user the same username as the previous new user thus duplicating names.

#45

noahb - October 22, 2009 - 19:51
Status:needs review» needs work

that's not good at all...

#46

noahb - October 23, 2009 - 09:44
Status:needs work» needs review

Here are some updates...

AttachmentSize
rg.patch 24.04 KB
realname_generate.zip 6.42 KB

#47

espirates - October 27, 2009 - 17:52

It's still happening with this new update, it's renaming the new user to the user who signed up previously.

I have new accounts set for approval by admin so when I get the notice, I edit the account, correct username displays initially but when I hit save, it replaces the username.

#48

noahb - October 27, 2009 - 18:28
Status:needs review» needs work

@espirates

Really sorry about all the trouble that this is causing you... I appreciate you taking the time to give me some more details, which I think have given me a hint as to why this bug is happening... I'll post another update (hopefully) later today...

#49

noahb - October 28, 2009 - 03:35
Status:needs work» needs review

and another...

AttachmentSize
rng3.patch 26.48 KB
realname_generate.zip 6.93 KB
 
 

Drupal is a registered trademark of Dries Buytaert.