Michael's method is probably a better choice, but I think it would also work to protect the page with a snippet rather than access control.The snippet would forward unauthorized users to the login page. I think the redirect to prior would then work.Thanks, well I gave Load access to the Anonymous group, and have set up a basic snippet on one of the pages as a test, but when I browse to it (thinking it would forward me to the Login page as I'm not logged in) it just brings up a blank page.
if (!$modx->user->hasSessionContext($modx->context->get('key'))) { $modx->sendForward(10); }
This is the default behavior when configured correctly.I've done exactly as suggested, including using sendForward in the snippet. The URL of the requested page displays in the browser bar. But after login, I get sent to the home page- even though my unauthoriased page is set to the Login page, I've removed the loginResourceID from the login snippet and the action from the login tpl....
To get this:
anonymous Users need to have "Load" priviliges to this resource group. So When you click em, you get an 301 Unauthorized instead of an 404 Not Found.
You need to configure the unauthorized_page to your Login-Page
The Login Page Form, should not have an action
The Login Snippet should have no loginResourceId
Then you just Link to the member Pages, or users click them out of their favorites, history, etc.
Modx uses an sendForward to display the login Page, with the url of the previous Page. As Soon as the Users is logged in, they will stay on the url, seeing the member content.
That usually means that either the user doesn't have permission to see the page, the page isn't published, or the page doesn't exist. In all those cases, the user is sent to the page specified in the error_page System Setting, not to the page set as the unauthorized_page.
Sending users to the unauthorized_page is tricky, but I'd recommend getting things working before worrying about that.
<?php /** * * redirectToRequestedOnLogin * * Plugin detects unauthorised access attempts and redirects * to requested URL on successful login. * * Requirements * * Use in conjunction with Login Extra. Do not define the following properties in the Login Snippet call: * * - loginResourceId - this overrides the resource the Plugin tries to redirect to * - redirectToPrior - not needed * * Example Login shippet call: * * [[!Login? &logoutResourceId=`87` ]] * * * Manually set Plugin to fire on events: * - OnPageUnauthorized * - OnWebLogin * * Credits * - http://forums.modx.com/thread/44577/want-to-be-able-to-send-not-autorized-user-back-to-the-page-they-requested * - http://forums.modx.com/thread/16338/return-the-current-page-s-full-url * - http://forums.modx.com/thread/44828/redirect-to-login-page?page=2#dis-post-397761 * */ if (!isset($modx)) return ''; // don't process plugin on manager context, add multiple contxts to the array if required $excludeContext = array('mgr'); if (in_array($modx->context->get('key'), $excludeContext)) return; // figure the event that triggered the plugin $eventName = $modx->event->name; // carry out actions depending on event that triggered plugin switch($eventName) { case 'OnPageUnauthorized': // grab the id of the restricted page requested by the user $id = $modx->resourceIdentifier; //$modx->resource->get('id'); - fails // set session to hold requested id $_SESSION['unauthorisedRequestID'] = $id; // option to log session value for unauthorisedRequestID // $modx->log(modX::LOG_LEVEL_ERROR, '[redirectToRequested] unauthorisedRequestID set to: ' . $_SESSION['unauthorisedRequestID'] ); break; case 'OnWebLogin': // handle redirect to requested id that forced login // continue only if session set if ( !empty( $_SESSION['unauthorisedRequestID'] ) ) { $redirectUrl = $modx->makeUrl( $_SESSION['unauthorisedRequestID'], "", "", "full" ); // option to log the full url user will be redirected to // $modx->log(modX::LOG_LEVEL_ERROR, '[redirectToRequested] redirecting to ' . $redirectUrl ); // clean up if ( !empty( $_SESSION['unauthorisedRequestID'] ) ) { unset( $_SESSION['unauthorisedRequestID'] ); } // send the redirect $modx->sendRedirect( $redirectUrl ); } else { // redirect user to login home resource, in this case #2 // should change this to a system setting so that it can be edited easily through the manager settings $redirectUrl = $modx->makeUrl( 2, "", "", "full" ); // $modx->log(modX::LOG_LEVEL_ERROR, '[redirectToRequested] sending to #2' ); // send the redirect $modx->sendRedirect( $redirectUrl ); } break; }