$user->joinGroup('Premium') and $user->leaveGroup('Gold')moduser/getUserGroupNames()
moduser/getUserGroups()
moduser/isMember($groups,$matchAll = false)
$groupNames= $this->getUserGroupNames();
$_SESSION["modx.user.{$id}.userGroupNames"]$_SESSION["modx.user.{$id}.userGroups"]unlink('core/cache/context_settings/manager/context.cache.php');
return;I can't answer most of those questions, but this might work (or not):
In a plugin connected to OnUserAddToGroup or OnUserRemoveFromGroup:
unlink('core/cache/context_settings/manager/context.cache.php'); return;
(Change 'manager' if you've renamed the manager folder.)
If that doesn't work, you might be able use the same plugin to alter the $_SESSION array manually (if you can figure out its structure) to change the user's group membership.
if($ext['needToRefreshSession']){
// remove session
$key = "modx.user.{$user->id}";
$keyLength = strlen($key);
foreach ($_SESSION as $sKey => $sVal) {
if (substr($sKey, 0, $keyLength) === $key) unset($_SESSION[$sKey]);
}
$user->addSessionContext('web');
$_SESSION["modx.web.user.token"]= $user->generateToken('web');
$ext['needToRefreshSession'] = 0;
$profile->set('extended',$ext);
$profile->save();
}That look like a great solution. How is that code triggered? How is $ext['needtoRefreshSession'] set above this code?
Do you mind if I do a blog post on this?

$redirect_url = $modx->getOption('redirect_url',$scriptProperties,$modx->getOption('redirect_url',$_REQUEST));
if(!$modx->user->isAuthenticated('web')){
// Send to unauth page -> invite to login
return $modx->sendRedirect($redirect_url);
}
$user = &$modx->user;
$profile = $modx->user->getOne('Profile');
$ext = $profile->get('extended');
/**
* verify session
*/
if($ext['needToRefreshSession']){
// remove session
$key = "modx.user.{$user->id}";
$keyLength = strlen($key);
foreach ($_SESSION as $sKey => $sVal) {
if (substr($sKey, 0, $keyLength) === $key) unset($_SESSION[$sKey]);
}
$user->addSessionContext('web');
$_SESSION["modx.web.user.token"]= $user->generateToken('web');
$ext['needToRefreshSession'] = 0;
$profile->set('extended',$ext);
$profile->save();
}
return $modx->sendRedirect($redirect_url);
[[!~[[++inp.connectorPageID]]? &scheme=`full` &action=`refreshAndRedirect` &redirect_url=`[[~[[++inp.exampleOfDestinationPageID]]? &scheme=`full`]]`]]

Just a thought: instead of bothering with the user's extended profile fields, how about just setting $_SESSION['needToRefreshSession'] ? Then your code could go in a plugin attached to OnHandleRequest or some other generic event that occurs before page permissions are checked.
Thanks,
Just a thought: instead of bothering with the user's extended profile fields, how about just setting $_SESSION['needToRefreshSession'] ? Then your code could go in a plugin attached to OnHandleRequest or some other generic event that occurs before page permissions are checked.
$user->getOne('Profile');$ext = $profile->get('extended') or manually execute the $ext = json_decode($user->extended, 1);How can you set user $_SESSION if you change his groups from MODX manager with your admin account? That's why I used User Extended Field.