Maybe too late, but for those solving user redirect on login, this is working postHook for me:
<?php
if($_REQUEST['service']=='login'){
$redirs['group1'] = '11';
$redirs['group2'] = '23';
$user = $modx->getObject('modUser', array('username' => $hook->getValue('username')));
foreach ($redirs as $group => $id){
if ($user->isMember($group)){
$url=$modx->makeUrl($id);
$modx->sendRedirect($url);
}
}
}
return true;
You cannot use
$modx->user to get the user just logged in (as stated in Login docs), but you can use
username from login form. This posthook fires after user is already authenticated, so I consider using username directly as safe method.
Also, I have added check if this is login or logout request, otherwise this postHook would fire with logout as well.
There should be some other checks for $user validity and some nicer way to specify redirs array as snippet parameter, but as a starting point this should work.