I have a script that works with VisionCart to automatically log in a user, similar to
http://www.hyper-typer.com/news/auto-login-on-registration-modx-revolution"" target="_blank" rel="nofollow">this one by Joe Molloy. I'm trying to take this to the next level, and speed up checkout even more by taking the user straight to the page where they enter their shipping address, etc., and using their email address, and an auto-generated, hidden password field to log them in. Here is my code:
$vc =& $modx->visioncart;
if (!$modx->user->isAuthenticated()) {
$modx->runSnippet('Register',array(
'submitVar' => 'vc_user_form',
'activation' => 0,
'usernameField' => 'email',
'usergroups' => 2,
'postHooks' => 'autoLogin',
));
}
$processor = $modx->runProcessor('user/update', $scriptProperties['fields'], array(
'location' => 'web',
'processors_path' => $vc->config['processorsPath'],
'hook' => &$hook
));
return $processor->getResponse();
This actually almost works. The auto-login snippet referenced by the post hook on the Register call does in fact log the user in:
$c = array(
'login_context' => 'web',
'username' => $_POST['email'],
'password' => $_POST['password']
);
$response = $modx->runProcessor('security/login',$c);
The trouble is that the call to the user update processor fails because, as I discovered with the incomparable xDebug, $modx->user still points to the anonymous user, even after the auto-login script runs. Thus, I get an error. Reload the page, and everything works fine - the user is logged in, and if I fill out the form again and resubmit it, the user record is updated with the form information.
The question, then, comes down to this: Is there something I can add to the auto-login script that will fully log the user in id-script, before the page is reloaded?