Generate Usernames

2 years 2 months ago #328299 by 3by400Inc
Generate Usernames was created by 3by400Inc
We’re needing to auto-generate random usernames at registration in the following form:
“E”+ dechex(time())

We’ve tried a few different approaches that haven’t worked yet:

— CB AutoAction that generates the username value before or after the registration form is displayed

— AutoAction that generated the username at registration save

— Code field used to generate and return the random value and then the field set as the username fallback. (in this attempt the username always set to the email, as if the code field was empty.)

Please Log in to join the conversation.

2 years 2 months ago - 2 years 2 months ago #328306 by krileon
Replied by krileon on topic Generate Usernames
Do the usernames absolutely have to be in that format? If not you can enable random username fallback in CB > Configuration > User Profile then remove the username field from registration display and it will randomly generate on on registration.

You're going to have a hard time trying to do this with CB Auto Actions as username needs to be set really early. Probably the only way would be to use onStartSaveUserRegistration trigger with a Code action and Method set to PHP then write the necessary PHP to set a username on the var1 variable which is the user object. Example as follows.

Global
Triggers: onStartSaveUserRegistration
Type: Code
User: Automatic
Access: Everybody
Action
Method: PHP
Code:
$variables['var1']->set( 'username', 'E' . dechex( time() ) );
Parameters
References: Variable 1

That should work for setting the username early enough.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 years 2 months ago #328309 by 3by400Inc
Replied by 3by400Inc on topic Generate Usernames
Yes, we need that format because users are created in other integrated systems in that format.

I actually tried a CB Auto Action like the one you outline after finding a forum topic about using the same trigger to set a random email address.

I'm not sure if I was missing something, but I couldn't get it to work.

So there's no way to generate the string in a code field and have the code field be the fallback at registration?

Please Log in to join the conversation.

2 years 2 months ago #328316 by krileon
Replied by krileon on topic Generate Usernames
Does my above example not work for you? My example assumes you aren't using the username field. If you are then the above won't work since the value in the fields input will be bound to the user object after that trigger.

So there's no way to generate the string in a code field and have the code field be the fallback at registration?

No, not at this time. The fallback works with raw values only so it only works with stored fields.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 years 2 months ago #328334 by 3by400Inc
Replied by 3by400Inc on topic Generate Usernames
No, the CB Auto Action is not working. Instead, the username is stored as the fallback field, which I currently have set to email.

Please Log in to join the conversation.

2 years 2 months ago #328335 by 3by400Inc
Replied by 3by400Inc on topic Generate Usernames
Also, to clarify, we do not have the username field displayed on the registration form so the user is not supplying a field value at registration.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.279 seconds