This simple patch adds 3 settings under administer >> settings >> user, to allow the admin to change where users are redirected after they 1) register, 2) login and 3) logout.

While this is technically a new feature, I consider this a usability enhancement and it's something that is people could really use, and it's a simple enough patch that it should be relatively easy to test and ensure that it breaks nothing.

Comments

m3avrck’s picture

StatusFileSize
new4.81 KB

This patch cleans up the wording and also the issue of <front> not showing up in the help text. Tested and working great, I'd say this is RTC!

Jaza’s picture

Version: 4.7.0-beta2 » x.y.z
StatusFileSize
new5.15 KB

This patch moves the new form items to their own fieldset, "User redirection settings", as they don't (all) belong in the registration settings fieldset.

Also converted the patch to use UNIX linebreaks, and removed unneeded blank lines from bottom of the file (this was causing the patch utility to give warnings).

m3avrck’s picture

StatusFileSize
new5 KB

Sounds good to me, updated against HEAD.

moshe weitzman’s picture

Status: Needs review » Needs work

if you make destination a hidden form field, then you can remove the parameters to drupal_goto(). drupal_goto already checks the $_REQUEST for a field called destination and redirects accordingly. saves a few characters.

i do have some reservations though. these preferences will override any on the querystring. I might have a link like q=user/login?destination=taxonomy/term5 from a certain part of my site. but with this patch my specified destination would be ignored. would be good to smarten the patch to recognize this circumstance. just check for existence of $_REQUEST['destination']

merlinofchaos’s picture

Status: Needs work » Needs review
StatusFileSize
new5.42 KB

Try this version

moshe weitzman’s picture

Um, I'm pretty sure you can replace as follows:

- drupal_goto($_REQUEST['destination'] ? $_REQUEST['destination'] : ($form_values['destination'] ? $form_values['destination'] : NULL));
+ drupal_goto();

drupal_goto() already does what you seek. My only gripe is that you add a destination param to the form even when one has been supplied in the URL. Thats clobberring.

merlinofchaos’s picture

I'm quite sure drupal_goto won't check $form_values['destination'] if $_REQUEST['destination'] doesn't exist.

I'm not sure I see how adding 'destination' to the form even if one was in the URL already (and at that level I find it unlikely there was a destination in the URL, but someone could do it, sure) is clobbering.

moshe weitzman’s picture

Status: Needs review » Needs work

if you change the following to a hidden field, then you can simplify the drupal_goto() calls as I suggest: $form['destination'] = array('#type' => 'value', '#value' => variable_get('user_post_login_page', 'user'));

some modules change the 403 acces denied into a login page with the proper destination. in this case, we don't want the user going to the admin decided destination - he already had a destination in mind! thats what i mean by clobber. my suggestion is to not lay down the hidden field at all if isset($_REQUEST['destination'])

merlinofchaos’s picture

But that's why there is the check in the drupal_goto() statement.

Ok, it's true that you could do an if isset() before the $form['destination'] statement, and instead your drupal_goto looks like

drupal_goto(isset($form_values['destination']) ? $form_values['destination'] : NULL)

which I don't really see as being either better or worse than the one that's already there.

merlinofchaos’s picture

We could also write the dest directly into ['destination'] but that means fiddling with '#name' => 'destination' which I suppose is ok.

moshe weitzman’s picture

how about reviving this?

LAsan’s picture

Version: x.y.z » 7.x-dev

how about reviving this?

Moving to cvs.

lilou’s picture

Title: Admins have no control over post-user login/registration activities » Custom redirection after register, login and logout
swentel’s picture

Status: Needs work » Needs review
StatusFileSize
new5.94 KB

Totally support this patch. Didn't apply anymore of course with all the filename changes and function moves. Reapplied it to cvs, untested, so please review!

Anonymous’s picture

Subscribing. So what's logintobbagan to do now? ;p

dave reid’s picture

Status: Needs review » Needs work

This patch really does not need to check for $_REQUEST['destination'] since drupal_goto handles that automatically. If there is a $_REQUEST['destination'], the extract() in drupal_goto will overwrite the current path parameter.

sun’s picture

Ugh. Found this issue too late.

Got a working patch for a custom logout path in #452462: Allow custom logout page - shall I move that patch over here?

I basically agree that admin/user/settings may be a more accurate location to place these settings. (I added to admin/settings/site-information, where front page, 403, and 404 are located already.)

sun’s picture

Title: Custom redirection after register, login and logout » Add trigger/action for custom after-register, after-login and after-logout events
StatusFileSize
new2.82 KB

Marked #452462: Allow custom logout page as duplicate of this issue. In there, people suggested to simply use triggers/actions for this purpose, which not only makes sense, but also allows further customizations.

Re-attaching my patch from the other issue (only for reference).

@merlinofchaos: Are you still up for working on this?

tstoeckler’s picture

Without actually having tested it:
Custom redirect page after register is possible by using the "After a user account has been created" trigger and adding a redirect action, which is actually possible. I'm at least guessing that's what's the trigger is for, that would have to be validated.

Custom redirect on login is there with triggers and actions, even though it doesn't work as I recently noted in #451498: Redirect on login broken with action/triggers. As I noted there I assume this is due to some special-casing in user.module for the login process.
I don't know if #451498 should be marked "duplicate" if there is an approach here or if that should be handled seperately as it's really a bug report.

Custom redirect on logout would theoretically be possible...:
Well, there is the "After a user has logged out" trigger, but the problem is, you can't assign a redirection action to that trigger (as I noted in #452462: Allow custom logout page). I have no clue whether there is a reason for that or if that problem could simply be solved by making that action available.

Just some notes for now, I hope to play around with all this a little more in the next days.

sun’s picture

And again, someone in IRC asked "How can I redirect users to a certain page after login?"

crotown’s picture

I just marked #451498: Redirect on login broken with action/triggers as a duplicate of #286668: Trigger "User logging in" doesn't work with Action "Forward to URL". Note that a solution for the after-login redirect is proposed there. The patch solves the problem for me in the latest head.

I agree that the idea that we should not duplicate (and conflict) with things already there in actions/triggers. We should simply make sure the options that are already there in actions/triggers work.

tstoeckler’s picture

I tested the patch at #286668: Trigger "User logging in" doesn't work with Action "Forward to URL" and it works. I've rerolled it for D7. So we need to review and commit that. That gets us a third of the way.

Custom page upon registration: Is theoretically possible with actions/triggers.
I tried it, and upon registration you are redirected to the page, but you are not logged in, which isn't expected behaviour. Without the redirect action, you are logged in, after registration. I tried the patch, from #286668: Trigger "User logging in" doesn't work with Action "Forward to URL", but that didn't work either. So that needs to figured out.

Custom page on logout: Still the same as in #19

Andrew Himes’s picture

subscribe

sun’s picture

Issue tags: +API clean-up

Introducing a new tag for feature freeze: API clean-up.

sun’s picture

Assigned: merlinofchaos » Unassigned
Category: feature » task
Issue tags: +D7 API clean-up

It would really really be nice if someone would step up now to provide a patch for this.

andypost’s picture

Main problem for redirects is in conflict of drupal_goto() with drupal_get_destination

Patch #286668: Trigger "User logging in" doesn't work with Action "Forward to URL" is simple

 function system_goto_action($object, $context) {
+  unset($_GET['destination']);
   drupal_goto(token_replace($context['url'], $context));
 }

And this allows to proceed to a redirect page because user_login_block sets 'destination'

function drupal_goto($path = '', array $query = array(), $fragment = NULL, $http_response_code = 302) {
  if (isset($_GET['destination'])) {
    extract(drupal_parse_url(urldecode($_GET['destination'])));
  }

We have no ability to write good tests for triggers as explained #20 at #286668: Trigger "User logging in" doesn't work with Action "Forward to URL"

andypost’s picture

Status: Needs work » Active
sun’s picture

Version: 7.x-dev » 8.x-dev
Status: Active » Needs work
Issue tags: -D7 API clean-up

Sadly, this didn't make it.

asb’s picture

sub

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

avpaderno’s picture

Version: 8.6.x-dev » 8.7.x-dev
Issue summary: View changes

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.