Auto Remove User from Group?

Permalink
I'm setting up a webform on a page that I'll be giving limited access to clients. As soon as they hit submit on the form, I want them to no longer be able to access the form page.

I was thinking that if there's some way to add a block or hardcode something into the 'Thank You' page template that automatically removes their permissions or group assignment, that could work. However, I have no idea how to do something like that or if there's a better way to do what I'm trying to do.

Is this possible with C5?

Thanks.

 
TNTdesign replied on at Permalink Best Answer Reply
Looking into this further, this is how you would remove someone from a particular group:

$g = Group::getByID(4);
$u = new User();
$u->exitGroup($g);


However, when a user is added to a group while they're logged in, the permissions for that group don't go into effect for that user until they log out and then log in again. So, I ended up removing them from the group that has access to the form and then forcing a logout with /login/logout on the forms 'Thank You' page, which reset the permissions. Not super user friendly but for what I'm trying to do, it'll be fine.

On the actual 'Thank You' page that my form redirects to, I added this to the top of the page:

$g = Group::getByID(4);
$u = new User();
if($u->inGroup($g)) {
   $u->exitGroup($g);
   header( 'Location: /login/logout' ) ;
}