Advertisement

Redirect after password reset

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Redirect after password reset

Post by davidhharnett » Wed Aug 14, 2013 12:32 pm

Hello,

A strange request but due the nature of the way I am using my joomla install I need the redirect after a user resets their password to go back 3 pages to the original url (which is not fixed) that they where trying to visit. Can anyone think of a way to do this, it is basically the same functionality you get when you try to log in using the login component and you use the wrong username/password when you eventually get it right it will take you back to the original page.

Any ideas to point me into the right direction?

Many Thanks
David

Advertisement
User avatar
ionut
Joomla! Ace
Joomla! Ace
Posts: 1264
Joined: Thu May 27, 2010 1:00 pm
Location: EU

Re: Redirect after password reset

Post by ionut » Wed Aug 14, 2013 5:07 pm

How do you send the user from the original page to the reset page? Do you have a link on all pages that points to registration page? Can you give more examples on what you are trying to do, or maybe to even give a link to your website so we can have a better idea on what you are trying to achieve.

davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Re: Redirect after password reset

Post by davidhharnett » Wed Aug 14, 2013 5:19 pm

Hi,

So basically if someone registers I use redirect on login to make sure that they auto login and redirect back to the referrer page. then I have used Ajax register to ensure that no-one can submit an incorrect form on the register page to ensure that the referrer page is the previous page but this is not possible with the reset page as there is three links to go through before you finish. See the link below and register then reset the password if you like.

http://hhost1.com/h2g/index.php/aquilareg

User avatar
ionut
Joomla! Ace
Joomla! Ace
Posts: 1264
Joined: Thu May 27, 2010 1:00 pm
Location: EU

Re: Redirect after password reset

Post by ionut » Thu Aug 15, 2013 7:26 am

I have done all these, but you didn't told me why exactly you need this 3 steps back solution. Since after reset password step I'm being redirected to the login page which seems to be the right solution.

davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Re: Redirect after password reset

Post by davidhharnett » Thu Aug 15, 2013 8:02 am

Hello,

Thank you for looking into this the issue is it needs to go back to the original link (http://hhost1.com/h2g/index.php/aquilareg) and not the login component (the original link uses login module) otherwise when you log in you are redirected to a fixed page (currently index.php) and the nature of this site means that you are then lost because there is no menu structure or way to click to the original link. This is because each link is effectively a self serving white label site that gets e-mailed to people.

Does that make sense? I know this is a really odd way of doing things I have never had to build a site like it before!

User avatar
ionut
Joomla! Ace
Joomla! Ace
Posts: 1264
Joined: Thu May 27, 2010 1:00 pm
Location: EU

Re: Redirect after password reset

Post by ionut » Thu Aug 15, 2013 8:16 am

So, try this way. On your server locate

Code: Select all

<joomla root>/components/com_users/controllers/reset.php
Make sure you create a backup for this file.
Inside this file, search for "public function complete" and go to the last part of code

Code: Select all

	// Complete succeeded.
			// Get the route to the next page.
			$itemid = UsersHelperRoute::getLoginRoute();
			$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
			$route	= 'index.php?option=com_users&view=login'.$itemid;

			// Proceed to the login form.
			$message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS');
			$this->setRedirect(JRoute::_($route, false), $message);
			return true;
Here replace this part of code with

Code: Select all

	// Complete succeeded.
			// Get the route to the next page.
			$route	= 'http://hhost1.com/h2g/index.php/aquilareg';
			$message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS');
			$this->setRedirect( $route, $message);
			return true;
This should work. The only minus is that in case of Joomla update it might overwrite this file, so you'll need again to make this change.

davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Re: Redirect after password reset

Post by davidhharnett » Thu Aug 15, 2013 8:22 am

You are an absolute hero! That did exactly what I needed thank you so much. I have a couple of other core changes on this site and have them documented for updates so thats no issue.

Really appreciate you taking the time to help me here!

davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Re: Redirect after password reset

Post by davidhharnett » Thu Aug 15, 2013 8:24 am

Ahh sorry I just got a little too excited there and didn't read the code is there any way of changing it from the actual absolute url to a dynamic redirect of the referrer url because it will not alway be
http://hhost1.com/h2g/index.php/aquilareg

It could be any url?

Sorry to keep asking I will take a look myself as well.

User avatar
ionut
Joomla! Ace
Joomla! Ace
Posts: 1264
Joined: Thu May 27, 2010 1:00 pm
Location: EU

Re: Redirect after password reset

Post by ionut » Thu Aug 15, 2013 8:38 am

So, let me understand, you will have more pages like http://hhost1.com/h2g/index.php/xxxxx and you want based on the page to have your user redirected to proper page?

davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Re: Redirect after password reset

Post by davidhharnett » Thu Aug 15, 2013 8:41 am

Yes this is what I am trying to achieve, can you think of a way to do it? It is in the same way the that the login component works when you log in successfully it takes you back to the page you where trying to visit.

User avatar
ionut
Joomla! Ace
Joomla! Ace
Posts: 1264
Joined: Thu May 27, 2010 1:00 pm
Location: EU

Re: Redirect after password reset

Post by ionut » Thu Aug 15, 2013 9:00 am

Let's try this way. It's more code hacking but I hope it will do the job for you. Remember to backup each file we'll affect.
Go to

Code: Select all

<joomla root>/components/com_users/models/reset.php
Inside function populateState() add the following code:

Code: Select all

$referer = JFactory::getApplication()->getUserState('site.referer');
if (empty($referer)) {
$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; 
JFactory::getApplication()->setUserState('site.referer', $referer);
}
This will keep in session the actual referer url when the user tries to reset the password.
After this inside the file you have already made the modifications (/components/com_users/controllers/reset.php), instead of the code I have provided first time, write this code

Code: Select all

// Complete succeeded.
// Get the route to the next page.
$referer = JFactory::getApplication()->getUserState('site.referer');
JFactory::getApplication()->setUserState('site.referer', null);
$message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS');
$this->setRedirect( $referer, $message);
return true;
Make this modifications and let me know if it works.

davidhharnett
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sun Dec 21, 2008 12:21 pm

Re: Redirect after password reset

Post by davidhharnett » Thu Aug 15, 2013 9:14 am

Hi, That seems to have cracked it! You are an absolute genius once again thank you for taking the time to help!!

User avatar
ionut
Joomla! Ace
Joomla! Ace
Posts: 1264
Joined: Thu May 27, 2010 1:00 pm
Location: EU

Re: Redirect after password reset

Post by ionut » Thu Aug 15, 2013 9:21 am

You are welcome, I'm glad it worked :)

Advertisement

Locked

Return to “General Questions/New to Joomla! 2.5”