Adding users to group programmatically during registration
Permalink
Hello,
On my website users can register, and choose one of two groups to be assigned to. The functionality of the website for each users depends on the group they are in.
I've therefore overridden the single_pages/register.php and controller/single_pages/register.php.
Then I've added two radio buttons to my registration form, to have a user select one of two groups to be added to.
I'm able to fetch the value of the radio button in the controller page, and have tested this by appending the value to the username while registering, this works.
However after this code in the controller:
I've added this piece of code, to add users into the specified group.
Also, i've added
to the top of the file, and changed Concrete\Controller\SinglePage; to Application\Controller\SinglePage;
This however doesn't add users to groups.. Can anyone help me with this problem?
On my website users can register, and choose one of two groups to be assigned to. The functionality of the website for each users depends on the group they are in.
I've therefore overridden the single_pages/register.php and controller/single_pages/register.php.
Then I've added two radio buttons to my registration form, to have a user select one of two groups to be added to.
I'm able to fetch the value of the radio button in the controller page, and have tested this by appending the value to the username while registering, this works.
However after this code in the controller:
// now we log the user in if ($config->get('concrete.user.registration.email_registration')) { $u = new User($this->post('uEmail'), $this->post('uPassword')); } else { $u = new User($this->post('uName'), $this->post('uPassword')); }
I've added this piece of code, to add users into the specified group.
if( $this->post('uGroup') == "group1" ) { $g = Group::getByName('group1'); } else { $g = Group::getByName('group2'); } $u->enterGroup($g);
Also, i've added
use Group;
to the top of the file, and changed Concrete\Controller\SinglePage; to Application\Controller\SinglePage;
This however doesn't add users to groups.. Can anyone help me with this problem?
No response on this? I'm looking for someone to help with registering users via form submission, and adding them to a group that way... so far no luck. Formify (add-on) can add users to a group upon form submission, but it doesn't register them. We're both missing pieces, and the C5 community is falling apart. If I get any headway on this, I will update you.
When you do it by new User(arg1, arg2) you wont get a new user. You need to call UserInfo::register($data) with a 'use UserInfo' after the namespace declaration. The $data should be an array with in minimum following key/value pairs:
another way can be found on:https://www.concrete5.org/community/forums/customizing_c5/creating-u...
$data['uName'] = $username; $data['uPassword'] = $password; $data['uPasswordConfirm'] = $passwordConfirm;
another way can be found on:https://www.concrete5.org/community/forums/customizing_c5/creating-u...