Skip to Content Skip to Menu

Autogenerate username from user id

  • boyjahq
  • boyjahq
  • OFFLINE
  • Posts: 473
  • Thanks: 33
  • Karma: 3
9 years 4 months ago - 9 years 4 months ago #265824 by boyjahq
Autogenerate username from user id was created by boyjahq
I would like to prevent users from choosing their own username. Rather, I would like it to be auto generated from their user id. I have created a field cb_usertype that is used to assign users to a specific user group (as per your tutorial).

If the user is usertype = 1, I would like to generate a username that is the userid prefixed by the letter "h" (i.e., username = h1284 where 1284 is the user id).

If the usertype = 2, I would like to generate a username that is the userid prefixed by the letter "w" (i.e., username = w2395 where 2395 is the userid). I would need for this username to be included in the email verification notice that is sent to the user. Is this possible with Auto Action? I have all latest CB and plugins as of 11 June 2015.
Last edit: 9 years 4 months ago by boyjahq.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
9 years 4 months ago #265843 by krileon
Replied by krileon on topic Autogenerate username from user id
Set the username field to not display on registration in CB > Field Management. Next within CB > Configuration > User Profile set "Username Fallback" to "Email" so it falls back to something unique. Now using CB Auto Actions create the following action.

Triggers: onAfterUserRegistration, onAfterNewUser
Type: Field
User: Automatic
Access: Everybody
Field: Username
Operator: Set (Field = Value)
Value: h[user_id]

This should provide what you're wanting.


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.
The following user(s) said Thank You: ricco1

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

  • boyjahq
  • boyjahq
  • OFFLINE
  • Posts: 473
  • Thanks: 33
  • Karma: 3
9 years 4 months ago - 9 years 4 months ago #266029 by boyjahq
Replied by boyjahq on topic Autogenerate username from user id
Thank you for this advice. Since I have 2 types of users, I need to put a condition in this action. When I set the condition to cb_usertype Equal To 1, the action should create the userid h[user_id]. Adding this condition does not seem to work. Debug shows: string(67) ":: Action 3 :: Conditional 1 failed for 454: cb_usertype Equal To 1". It seems that this action is not receiving cb_usertype data.

I have other actions that use the same condition to assign users to a user group based on cb_usertype and they are working.

I have tried also using the Does Contain in the condition, but the debug error is the same.

Actually, if I am using CB Subs as well, would it be better to do some or all of this within that plugin, including the use of SQL Actions?
Last edit: 9 years 4 months ago by boyjahq.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
9 years 4 months ago - 9 years 4 months ago #266057 by krileon
Replied by krileon on topic Autogenerate username from user id
The condition needs to be a valid substitution. So you'd need to use the below.

[cb_usertype] Equal To 1

See the below for further substitution usage information.

www.joomlapolis.com/support/tutorials/107-use-cases/18353-using-substitutions-throughout-cb

Actually, if I am using CB Subs as well, would it be better to do some or all of this within that plugin, including the use of SQL Actions?

You might be able to use CBSubs CB Field to change the username.


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: 9 years 4 months ago by krileon.

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

  • boyjahq
  • boyjahq
  • OFFLINE
  • Posts: 473
  • Thanks: 33
  • Karma: 3
9 years 4 months ago #266118 by boyjahq
Replied by boyjahq on topic Autogenerate username from user id
Thank you--you are correct as I did not enclose the substitution in brackets as I had done with the other auto actions and I apologize for missing it myself and wasting your time. It now works as you said it would.
The following user(s) said Thank You: nant

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

  • boyjahq
  • boyjahq
  • OFFLINE
  • Posts: 473
  • Thanks: 33
  • Karma: 3
9 years 4 months ago #266129 by boyjahq
Replied by boyjahq on topic Autogenerate username from user id
I would like to change the procedure a bit. I will use a plan specific URL to access the registration page. For example:
index.php?option=com_comprofiler&task=pluginclass&plugin=cbpaidsubscriptions&do=displayplans&plans=1

Rather than the cb_usertype that I had originally asked about, I would like to to set the username based on the plan number that was used to access the registration page. For example, if plans=1 or plans=2 then I want to set the username to be h[user_id]. And if plans=3 or plans=6 I want to set the username to be w[user_id].

How can I capture the plan number when I enter the registration page? It is available in the URL and I can see in the page source code that it is also available as a hidden field: <input type="hidden" name="cbponlyplans" value="1" />

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

Moderators: beatnantkrileon
Powered by Kunena Forum