Skip to Content Skip to Menu

Frontend usergroup selection

5 months 4 days ago #338112 by pjfroelofs
Frontend usergroup selection was created by pjfroelofs
We are looking for a way to change the usergroup of a user from the frontend.
That particular field is only visible for superusers.

I know a superuser can log into the backend and change the usergroup.
But in our case we need a convenient frontend change.
We defined 3 different kind of users, and all have different access.
We only want to offer the options public, guest and registered.

Somewhere I read a post from Krileon saying:
“That's not normally something I'd recommend to allow on frontend, but it's doable combining a select fieldtype with a usergroup auto action (would require 1 auto action per select option).”

We defined a select fieldtype and now we are looking for the appropriate auto actions.
Can you help me with an example of such an auto action code?

Regards,
Patrick

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
5 months 4 days ago #338119 by krileon
Replied by krileon on topic Frontend usergroup selection
You'll need 3 usergroup auto actions for that. 1 for each usergroup option in your select field. Then you'd have the following.

Global
Triggers: onAfterUpdateUser, onAfterUserUpdate (covers fronted and backend user edit)
Type: Usergroup
User: Automatic
Access: All Non-Moderators
Conditions
Condition 1
Field: Moderators
User: Viewing User
Operator: Is
Condition 2
Field: YOUR_SELECT_FIELD_HERE
Operator: Equal To
Value: OPTION_VALUE_1_HERE
Condition 3
Field: Custom > Value
Custom Value: [var1_YOUR_SELECT_FIELD_HERE]
Operator: Not Equal To
Value: [var3_YOUR_SELECT_FIELD_HERE]
Action
Mode: Add Usergroups
Groups: USERGROUP_TO_ADD_HERE

This should ensure it can't be applied to moderator accounts, only moderators can apply it to non-moderator accounts, and that the field value actually changed. With the above example lets say I have the following field.

Field: cb_selectgroup
Options
Options 1
Value: public
Label: Public
Options 2
Value: guest
Label: Guest
Options 3
Value: registered
Label: Registered

Using the above auto action example I'd configure the following.

YOUR_SELECT_FIELD_HERE = cb_selectgroup
OPTION_VALUE_1_HERE = public
USERGROUP_TO_ADD_HERE = Public

You can use "Replace Usergroups" instead of "Add Usergroups" if you want to replace all other usergroups they have as well or you can add a second action row to remove other usergroups you don't want them to have when changing their usergroup through the field.


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: pjfroelofs

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

Moderators: beatnantkrileon
Powered by Kunena Forum