Jump to:
| Project: | Login Destination |
| Version: | 6.x-2.8 |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Here is what I'd like to do:
1. Regardless of role, if a user logs in after trying to access a protected page, redirect them to the page they were attempting to go to.
2. If the user logs in "as expected", they'll click on a login image and be directed to the /user page. In that case I want to redirect them to either the front page or to a specific page depending upon role.
I'm pretty sure I have #2 down based upon the snippets I've seen in the documentation. But I"m not exactly sure how to handle #1 above. I believe that's the default behavior of Drupal (after an access denied page login return the user to the page they were trying to access), so I think I just need to use a condition rule that applies only if they login from /user. But I'm not exactly sure.
Comments
#1
For #1, simply place a check in Login Destination's "preserve destination' options and users will be redirected to their original page after logging in. You should install the DEV version because it will also check to make sure there IS a destination path present, otherwise it will continue to run your snippet.
#2
Am I correct in assuming that unless "destination=" appears in the URL, there is no redirect to a protected page after a successful login? So if a user goes to a protected page which requires login, they are not redirected back to that page after login unless "destination=" is in the URL?
#3
Yes, that is correct. To return a user to the original destination there must be a 'destination=PATH' in the URL. This is where the destination is derived from and also how the logic determines if it should use a destination path and ignore the rest of the logic.
#4
To address your #1, I unchecked the "use destination" box and used the following PHP code:
if (isset($_REQUEST['destination'])) {return urlencode(drupal_get_path_alias($_REQUEST['destination']));
}
else {
// Use $_GET here to retrieve the original path in source form.
$path = isset($_GET['q']) ? $_GET['q'] : '';
$query = drupal_query_string_encode($_GET, array('q'));
if ($query != '') {
$path .= '?'. $query;
}
return urlencode(drupal_get_path_alias($path));
}
You may have to modify it to account for #2, but this worked like a charm for me.