× Joomla Facebook Connect support forum

Topic-icon Facebook Login Redirect

Active Subscriptions:

None
14 years 9 months ago #13085 by fb_100001852085900
Hi There,

On my site i have some content which is for registered users only. I've set it up so that if they do not have access to the requested page it will redirect to the JFBConnect login module which is loaded inside an article for the user to login. Once the user has logged in it will then be redirected to a menu item which i have selected in the component settings.

I'm trying to set up the component so that when they login they will redirect back to the previous page by setting the param "return" in the url. This is so the module knows where to redirect the user back to if this param exists. However this param only seems to work on the username/ password form which comes with the module, it seems to ignore the redirect when i click the "Login With Facebook" button. Is there a setting i'm missing or is there a bit of code which i need to tweak?

Hope this makes sense.
The topic has been locked.
Support Specialist
14 years 9 months ago #13124 by alzander
Replied by alzander on topic Facebook Login Redirect
Jon,
There's nothing you're missing, that's simply how JFBConnect works. However, I think there's an easy solution to what you're trying to do, and thinking about it, we may include it in the next release (or something shortly thereafter).

To make the change, you'll need to edit the /components/com_jfbconnect/libraries/facebook.php file. At the top of the 'initDocument' function, around line 70. A few lines in, you'll see some code for setting the $return variable. Update it to look like the following:
$queryReturn = JRequest::getVar('return', null);
if ($queryReturn)
  $return = base64_decode($queryReturn);
else
  $return = $uri->toString(array('path', 'query')); // this line is already there
This is untested code, but pretty straightforward. Basically, JFBConnect will see if there's already a return variable set in the URL (to redirect back to some other page), and if so, use it for it's own redirection instead of using the current URL.

Note though, if you have the Returning User Redirection setting enabled, that will still force the user to whatever page you have set for all users who login.

Please test this and let us know how it goes. Think it's simple, and makes sense, so we'll look into putting this into future releases. Your feedback will really help.

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

None
14 years 9 months ago #13137 by fb_100001852085900
Hi Alex,

Thanks for the code it worked once i set the option "Enable Returning User Redirection" to "No" just like you said.

However, i would still like to have the option "Enable Returning User Redirection" still enabled and redirect to the selected menu item only if the "return" variable does not exist in the url. I can see at line 194 in the loginregister controller is where it does the check to see where it should be redirected to on login but i don't know the component well enough to make the needed changes.

Hope you could help on this.
Regards
The topic has been locked.
Support Specialist
14 years 9 months ago #13163 by alzander
Replied by alzander on topic Facebook Login Redirect
Jon,
You can try the following, which sounds and looks right from a quick glance at the code for 3.4, but you'll need to test to make sure it works as you expect when logging in from different pages. We're revamping the login redirections a bit for the 4.0 release (coming out tomorrow/this weekend) to make the code cleaner, but the basic snippet below should still work.

In the /components/com_jfbconnect/controllers/loginregister.php file, at line 303, you'll see where we check if the login_redirect setting is enabled. Add another conditional to that line so it looks like the below:
else if ($configModel->getSetting('facebook_login_redirect_enable') && !$jfbcLibrary->initialRegistration && $return == "")
That should skip the returning user redirection if the return variable was set.

As always, test, and please let us know how that works out.. good or bad :)

Good luck,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 9 months ago #13179 by fb_100001852085900
Hi Alex,

Thanks for the reply, I tried the same code before mentioning it in previous post. The above code did not work because the $return variable will always be set, back in the file "facebook.php" in "/components/com_jfbconnect/libraries/" around line 80 we made a small change to add in my own custom return url if it exists:
$return = JRequest::getVar('return', null);
if(isset($return)) {
   $return = base64_decode($return);
} else {
   $return = $uri->toString(array('path', 'query'));
}

It will look for a return url, if that does not exist it gets the path and query section of the current url. This return url then gets sent to the controller at around line 123 here:
$loginLink = $uri->toString(array('scheme', 'host')) . JRoute::_("index.php?option=com_jfbconnect&task=loginFacebookUser&return=" . base64_encode($return), false);

When making the above change it ignored the menu item i had selected and just logged them into the same page. Hope that makes sense!

Thanks again for the help.
The topic has been locked.
Active Subscriptions:

None
14 years 8 months ago #13856 by fb_100001852085900
Hi Alex,

I added the code edits to the latest version and it works great!

Thanks
The topic has been locked.
Support Specialist
14 years 8 months ago #13869 by alzander
Replied by alzander on topic Facebook Login Redirect
Jon,
Fantastic! Glad to hear you got things going, and it's (hopefully) a pretty smooth process from here forward!

Good luck,
Alex
The topic has been locked.