Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] CB Auto Action to create random usernames

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
11 years 2 weeks ago - 11 years 1 week ago #235451 by OldLodgeSkins
Hi,

I've looked a little bit everywhere before asking, I'm using Auto Actions for the first time and I'm a little lost... So my first question is, is there a documentation somewhere?

My goal right now is to generate random user names when someone signs up. So obviously the user name field needs to be hidden on the registration form, and then I intend to have it generated, probably on an onStartSaveUserRegistration trigger right?
My problem is that if I do understand how to set up a condition for the action, I have no idea what to do to define the action itself... At that point I'm guessing having a small piece of JS or PHP code to generate a random string and then feed that into the user name field should do it... But how / where?

Thanks.

Seb.
Last edit: 11 years 1 week ago by OldLodgeSkins.

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
11 years 2 weeks ago - 11 years 2 weeks ago #235454 by OldLodgeSkins
Replied by OldLodgeSkins on topic Documentation for Auto Actions?
Wait a minute, I think I'm progressing...
I should have selected the "code" type, right?
So I can add a small JS or PHP function to generate a random string. Now I need to figure out how to store it into the user name field...

I've chosen the PHP(eval) method (I'm more at ease with PHP than JS) and added this in it:
Code:
function generateRandomString($length = 10) { return substr(str_shuffle(implode(array_merge(range(0,9), range('A', 'Z'), range('a', 'z')))), 0, $length); } $username=generateRandomString(25);

So I should now have a variable containing my random string... What would the next step be?

Edit: I'll also need to make sure that particular string doesn't match an existing user name of course... I'm probably going to have to call some CB internal functions (verify user name, store user name).
Last edit: 11 years 2 weeks ago by OldLodgeSkins.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48473
  • Thanks: 8281
  • Karma: 1443
11 years 2 weeks ago #235463 by krileon
Replied by krileon on topic Documentation for Auto Actions?
Please review the below topic carefully. It does exactly this except generates email addresses. The same usage can be applied to the username field.

www.joomlapolis.com/forum/153-professional-member-support/222611-auto-action-possible-to-generate-email-when-registering?limitstart=0

Basically with the above you're adjusting the POST value of the username field before Joomla/CB does anything with it. It's really the only time it can be done.


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.

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
11 years 2 weeks ago - 11 years 2 weeks ago #235464 by OldLodgeSkins
Replied by OldLodgeSkins on topic Documentation for Auto Actions?
This looks perfect. Thanks!

Edit: tested and working perfectly. B)
Last edit: 11 years 2 weeks ago by OldLodgeSkins.

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
11 years 2 weeks ago #235468 by OldLodgeSkins
Replied by OldLodgeSkins on topic Documentation for Auto Actions?
To check my random string against the list of existing user names, I guess I could make a direct request on the database... Is this the best way or is there a better solution?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48473
  • Thanks: 8281
  • Karma: 1443
11 years 1 week ago #235496 by krileon
Replied by krileon on topic Documentation for Auto Actions?
You really don't need to check it against the database. A random 12 character username has an extremely slim to none chance of being the same as another. As you appear to want random 25 character I believe you'll be just fine. At any rate if you want to see if it already exists you'd use the below CB API to do this.

Code:
global $_CB_database; $testUser = new moscomprofilerUser( $_CB_database ); $foundUser = $testUser->loadByUsername( $username ); if ( $foundUser ) { // Username Exists } else { // Username Does Not Exist }


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.

Moderators: beatnantkrileon
Powered by Kunena Forum