Skip to Content Skip to Menu

Generate Usernames

  • 3by400Inc
  • 3by400Inc
  • ONLINE
  • Posts: 119
  • Thanks: 11
  • Karma: 0
2 years 9 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 or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
2 years 9 months ago - 2 years 9 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:
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.
Last edit: 2 years 9 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • 3by400Inc
  • 3by400Inc
  • ONLINE
  • Posts: 119
  • Thanks: 11
  • Karma: 0
2 years 9 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 or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
2 years 9 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 or Create an account to join the conversation.

  • 3by400Inc
  • 3by400Inc
  • ONLINE
  • Posts: 119
  • Thanks: 11
  • Karma: 0
2 years 9 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 or Create an account to join the conversation.

  • 3by400Inc
  • 3by400Inc
  • ONLINE
  • Posts: 119
  • Thanks: 11
  • Karma: 0
2 years 9 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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum