There's probably a way to do it as you describe, but it might be simpler to just send them to the product page and put a snippet at the top of that page (or in the template) that redirects not-logged-in users to the Login page. Then user &redirectToPrior=`1` in the login page to send them back to the product page after logging in.
Thank you for your reply. That gets me a bit closer, but leave one glaring question:
Would that not circumvent the ACL in ModX? I was trying to avoid doing so.
What I would like to accomplish, without circumventing the ACL system, is:
IF
unauthenticated user attempted to access restricted page
THEN
redirect to login page
AFTER LOGIN
redirect user back to initially requested page
ELSE IF
unauthenticated user logs in from standard login form and has not attempted to access a restricted page
THEN
send the user to the standard "post login" page
What I was thinking is, if I could set a session variable storing the ID number of the unauthorized page, I could then redirect them back there instead of to the standard page that is shown after login.
If this value was not set, it would simply send them through to their "account" page where they would normally be sent.
I am trying to avoid forcing them to find the link they wanted to visit for a second time and instead just send them there after they authenticate.
Any ideas?
You're right that what I was suggesting wouldn't work with the page restricted by an ACL entry and if it's not protected that way, any logged-in user could see it.
The problem is that pages the user is not authorized to see don't exist as far as the browser is concerned and they don't show up in Wayfinder menus or getResources output. Unless you give all users "load" permission for all pages, they'll go to the error page rather than the unauthorized page.
I'm not saying that what you want to do is impossible, but offhand I can't think of an easy way to do it.
Have you figured out this part?
IF
unauthenticated user attempted to access restricted page
THEN
redirect to login page
AFTER LOGIN
redirect user back to initially requested page
ELSE IF
unauthenticated user logs in from standard login form and has not attempted to access a restricted page
THEN
send the user to the standard "post login" page
I need to do the same thing. Basically be able to show a link or teaser on the homepage, if not logged in then login, then redirect to originally requested resource.
Robert Tobys
Managing Partner
Green Goat Media
916.405.1279
Skype: roberttobys
One step in the right direction is to make the login page your error page (by setting the error_page) System Setting, and using this in the Login tag: