Topic-icon Still having trouble with redirects... what am I missing?

Active Subscriptions:

None
Hi Alex, I'm hoping you can help. I've read the other topics on this, but they seem older and I'm not sure they are still relevant.

Here's what I would LIKE to do:

- In a newsletter, send user a link to a menu item that requires authentication
- User clicks the link, and sees an intermediate screen asking him to log in.
- User logs in using Facebook, and continues to destination page

Here's what is happening:
- User clicks the link, and sees the Joomla (com_user) login page -- which I have customized to include the Facebook login button.
- User clicks the Facebook button, and the SAME page reloads, so now the user sees, "Are you sure you want to log out?" I understand why -- I have selected "Same Page".... but this is certainly not what I intend.

So, I tried SClogin, but now understand the the redirect URL specified in the module only applies with normal joomla loging credentials, not Facebook login.

Can you suggest a configuration that allows me to...
- Enable autologin and stay on the same page (I want this!), but also...
- Be more prescriptive with the login flow when needed?

I'm happy to hack the SCLogin module if that is what it takes... I've been struggling with this for over a week now, and just need a solution.

Thanks in advance!

Amy
The topic has been locked.
Support Specialist
Amy,
Thanks for pointing this out. We did a bit of digging today and see that when going to a registered menu item, like you mention, doesn't properly redirect back to the original page. There are cases that work (like clicking a Registered "Read More" link and some other cases that redirect to the login page), but not for menu items.

Since you said you're up for hacking a little, we have some code for you to try. We implemented it today and it's gone through some testing, but we'd love to have your feedback. The code to modify is in the /components/com_jfbconnect/libraries/provider/facebook.php file. Around line 408, you'll see:
$uri = JURI::getInstance();
        $return = $uri->toString(array('path', 'query'));
        if ($return == "")
            $return = 'index.php';
Remove those 4 lines and replace with:
$app = JFactory::getApplication();
        $state = $app->getUserState('users.login.form.data', null);
        $return = null;
        if (JRequest::getCmd('option') == 'com_users' && JRequest::getCmd('view') == 'login' && is_array($state) && isset($state['return']))
            $return = urldecode($state['return']);
        if (!$return)
            $return = urldecode(base64_decode($app->input->getBase64('return', '')));
        if (!$return)
        {
            $uri = JURI::getInstance();
            $return = $uri->toString(array('path', 'query'));
            if ($return == "")
                $return = 'index.php';
        }
Again, test, and let us know how it goes!

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 7 months ago #37338 by aphils
This works perfectly so far! Thank you so, so much. What a relief to get this working. :-)

Will this be integrated into the next release, or will I need to update this code every time I upgrade?

Thanks again!
The topic has been locked.
Active Subscriptions:

None
Hi Amy,

I think that the easiest way to achieve this would be to create a user plugin (/plugins/user) that contains the code that alex has provided you with. This would avoid having to 'patch' the change at every upgrade.

All you need is 2 files - an xml manifest and the plugin class (php) both named amycustomredirects for example. The code:
XML
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="user" method="upgrade">
	<name>User - Amy's Custom Redirects'</name>
	<author>Geraint Brown - MindYourBizOnline</author>
	<creationDate>Sep 2013</creationDate>
	<copyright>(C) 2013 Geraint Brown - MindYourBizOnline. All rights reserved.</copyright>
	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
	<authorEmail>[email protected]</authorEmail>
	<authorUrl>www.mind-your-biz-online.com</authorUrl>
	<version>1.0</version>
	<description>Redirects the user to the page they were viewing upon logging-in</description>

	<files>
		<filename plugin="amycustomredirects">amycustomredirects.php</filename>
		<filename>index.html</filename><!-- ensure a blank index.html is placed in the root of the package too -->
	</files>
	<config>
		<fields name="params">
		</fields>
	</config>
</extension>
The Plugin Class
<?php
/**
 * @copyright	Copyright (C) 2013 Geraint Brown - MindYourBizOnline, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_BASE') or die;

/**
 * An example custom profile plugin.
 *
 * @package		Joomla.Plugin
 * @subpackage	User.profile
 * @version		1.6
 */
class plgUserAmyCustomRedirects extends JPlugin
{
	/**
	 * Constructor
	 *
	 * @access      protected
	 * @param       object  $subject The object to observe
	 * @param       array   $config  An array that holds the plugin configuration
	 * @since       1.5
	 */
	public function __construct(& $subject, $config)
	{
		parent::__construct($subject, $config);
	}
	
   /**
     * ON LOGIN
     * 
     * Method to get the url of a user at the point of login
     * Then redirect them there after successful login
     * 
     * @param   object  $user       The user Object
     * @param   array   $options    The login options
     * @return  bool    true        Passed Login      
     */
   function onUserLogin($user, $options = array())
     {        
         // Check site - bail out if not the frontend
		 $app = JFactory::getApplication()
         if(!$app->isSite())
            return true;
		
		 /**************************
		  * ALEX'S CODE GOES HERE
		  **************************/
         
		 // Return 
         return true;

     }
}
Once you've created those files, copy alex's code into the onUserLogin method of the plugin class, save, place them both in their own directory, ZIP and install in the usual Joomla fashion and you're done!

Hope it helps!

Gez
The topic has been locked.
Support Specialist
Amy,
Thanks for the feedback on the fix. We've already checked into the codebase and it will be in the v5.2 release scheduled for about a month from now.

As always, should you need anything else, just let us know.

Finally, if you haven't already, please consider leaving a rating and review for JFBConnect, or our support, on the Joomla Extension Directory. It certainly isn't required, but is very appreciated:
extensions.joomla.org/extensions/social-...ook-integration/7215

Thanks,
Alex
The topic has been locked.
Support Specialist
Gez,
Actually, that'd be a bad thing to do. The onUserLogin function shouldn't be used to perform a redirect as the redirect will prevent any further execution. For example, JFBConnect imports the user profile *after* they have logged in.

Also, the code I provided above needs to be done before the user actually logs in because it's determining where the user will go after the login. To do that, we need to have the location of where the user was before they made it to the login in the first place.

Thanks for the contribution though, it's always great to have more feedback for our users!
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 7 months ago - 10 years 7 months ago #37354 by learnthrusong
That's precisely what the onUserLogin is used for surely?... It occurs straight after the user has been authenticated (onUserAuthenticate) and therefore it's the perfect place to 'intercept' and override the login form's return (well, the state var).

ADD
I'm using this approach to achieve exactly this based on a user's akeeba subscriptions, how many days they've been subscribed to calculate which group they should be placed in and which content category to redirect them to. I had no problems with this working with SCLogin too.

Cheers,

Gez
Last edit: 10 years 7 months ago by learnthrusong.
The topic has been locked.
Support Specialist
Gez,
I think it'd be possible to use the onUserLogin call, but *for the specific example above*, it's actually a little more difficult. We already have a bit of code to detect and use the 'proper' redirect for the user (which can come from multiple different places), so that's the best bit of code to update.

In your case with AkeebaSubs, the onUserLogin function is probably the best place to put your code as well as keeping it separate.

As mentioned though, this change will be in the next release to make sure the redirection is the best it can be, so it's pretty much a moot point now.

Thanks again for the feedback,
Alex
The topic has been locked.
Active Subscriptions:

None
Thanks for clarifying the difference Alex!

Kind Regards,

Gez
The topic has been locked.