I have started working on a CAS SSO module for MODX, and I have run into a bit of a wierd problem.
I am making my own login snippet which runs through an if clause (are you logged into cas - yes then do x).
When we get into that if statement, I run the following code. (Please presume for the purposes of this question that the user and password supplied match a created user in the MODX users area)
// Are we logged in?
$userId = $modx->user->get('username');
if ($userId == '(anonymous)') { // No we are not... So Login
$response = $modx->runProcessor(array(
'action' => 'login',
'location' => 'security',
'username' => $casAttributes['user_id'],
'password' => $casAttributes['password'],
'login_context' => 'web'
));
}
else { // Yes we are!
echo 'Logged in, user already was here, user ID is ' . $userId;
}
I then do a quick check, and the username is still 'anonymous'.
If however, I run the same bit of code in another snippet on another resource, it logs in fine. Then, if I go back to that resource, (on another browser tab) the correct user name shows up fine.
Any help or suggestions greatly appreciated!