In many site situations, you might want to allow your users to register for more than one purpose. For instance, you might have one registration for a store and one for commenting on a blog, or something like that. Now, MODx only allows one "unauthorized" page - the page to which all users will be tossed if when they attempt to load a protected resource, but it doesn’t make sense to serve up just one generic message like "Please register here." Instead, you might want it to say "Please register to add blog comments" if they’re trying to do that, or "Please enter your name and address" if they’re attempting to place an order in the store. See where I’m going with this?
Somebody suggested that a script could easily be written to customize the unauthorized page depending on what is being requested. My question really is, what is the best way to retrieve the ID of the page being requested when the unauthorized page is served? If I knew how to do this, I could easily develop a snippet to serve the correct content chunk and title depending on the URL requested. Or is there a better way to do that?
Thanks for any suggestions.
Jason
-
☆ A M B ☆
- 24,524 Posts
I don’t know about Revo, but in Evo there is a System event "OnPageUnauthorized" that is evoked before the user is redirected. Here is the function used for sending to the unauthorized page.
<?php> function sendUnauthorizedPage() {
// invoke OnPageUnauthorized event
$_REQUEST['refurl'] = $this->documentIdentifier;
$this->invokeEvent('OnPageUnauthorized');
if ($this->config['unauthorized_page']) {
$unauthorizedPage= $this->config['unauthorized_page'];
} elseif ($this->config['error_page']) {
$unauthorizedPage= $this->config['error_page'];
} else {
$unauthorizedPage= $this->config['site_start'];
}
$this->sendForward($unauthorizedPage, 'HTTP/1.1 401 Unauthorized');
exit();
}
A plugin could intercept this process, and redirect to different pages depending on the documentIdentifier of the page being processed. Or you could have the plugin store the page Id in the session, and then process that with a snippet in your unauthorized page to determine the message and links to display.
I would presume there is a similar event in Revo.
Thanks, Susan - that’s a very sensible suggestion. OnPageUnauthorized is still present in Revo, so I’ll look into customizing with that.
Jason
I haven’t tried any of this but,
OnPageUnauthorized fires before the user is redirected.
At that point, $modx->resource should be the page that the user tried to visit.
You should be able to just test that and forward the user wherever you want.
Just make sure you’re plugin redirects the user rather than returning or they’ll be passed on to the "official" unauthorized page.
Remember, too, that when a user tries to access a page they’re not authorized to see, they’re usually redirected to the error page, rather than the unauthorized page.
See the section here on "Unauthorized Versus Error Page" if necessary: