Hello,
here is what I'm trying to achieve. I want a website with 2 contexts: one public (basically a login page), the other one for members-only (basically, the rest of the website).
I want user to request membership by filling a form, then get an email to activate their account. Everything works so far: user receives email, then can follow the link and get their account activated.
Now, I want two things:
- authenticate the user who just activated their account
- redirect those user to the 'members only' section as they just became members.
The problem I encounter every time is that, from ConfirmRegister, it seems that the URL can not be generated properly if it points to a resource in an another context.
I ran an experiment to try to understand why it behaves like that and I am now stuck. Here is what I did.
On the public landing page (1) of the website, I have :
[[!Login?
&loginTpl=`lgnLoginTpl`
&logoutTpl=`lgnLogoutTpl`
&errTpl=`lgnErrTpl`
&contexts=`members,web`
&logoutResourceId=`0`
&logoutKey=`logout`
]]
[[!RedirectIfAuthenticated]]
Here is the code for RedirectIfAuthenticated (which was a dirty hack attempt to circumvent the more general problem):
if($modx->user->isAuthenticated('web')){
echo 'User Authenticated (web)';
} else {
echo 'Not Authenticated (web)';
}
if($modx->user->isAuthenticated('members')){
$url = $modx->makeUrl(3, 'members');
echo 'User Authenticated (members)';
echo 'URL: '.$url;
// $modx->sendRedirect($url);
return;
} else {
echo 'Not Authenticated (members)';
}
Finally, I have the confirmRegister page with the following:
[[!ConfirmRegister?
&redirectTo=`1`
&authenticate=`1`
&authenticateContexts=`members,web`
&errorPage=`98`
]]
Scenario 1: user creates an account, get the email, follow the link.
The user is properly redirect back to the first resource, the public page. RedirectIfAuthenticated indicates that the user is properly logged in to both web and members context. However, the url generated is empty.
Scenario 2: user logs out, then log back in using the Login snippet:
first, the user is properly logged out from both web and members context (great !) then properly logged back in to both context. This time, RedirectIfAuthenticated also provides a valid URL for the target page in the other context (and I can access it -- everything works).
Am I doing something wrong ? How come makeUrl can not generate the URL in one case but can in the other, even though the user seems to be genuinely authenticated both time ?
Miscellaneous information:
MODX Revolution 2.2.0-pl2 (traditional)
Login 1.7.3.
Thanks !