Page 1 of 1

Doesn't redirect back to files download after login

Posted: 03 Nov 2009, 15:24
by Bikerrr
Hi All,

I have following problem (and I think others too)..
I have files with Registered access level in Phoca Downloads. When I click on a file link (inserted via PhocaLink plugin) it redirects me to login page (as needed, because I'm not logged in). I fill in my user/pwd and it redirects me to home page instead of that file page (that is not correct, because I'm as usual user have to look for this page on the site again).
How to fix this? What I need to add to code to have redirection back to previous page after login?

Thanks!

P.S.
Link: http://alexp.cms-start.com/test/index.p ... &Itemid=27
(Joomla! Overview item in the left menu)
I click on Goodmail downloads link at the bottom of article. It redirects me to login page, and to home page after login

Re: Doesn't redirect back to files download after login

Posted: 05 Nov 2009, 14:13
by Jan
Hi, the login is a part of Joomla! so this cannot be changed in Phoca Download

there are two areas where you can login:

modul - here no changes will be done and you will be redirected to the site where you are
component - here you will be redirect back to default page. You can set it in com_login parameters where to redirect after login (menu link)

Jan

Re: Doesn't redirect back to files download after login

Posted: 09 Jan 2010, 18:49
by Jan
Hi, thank you for sharing this information.

Jan

Re: Doesn't redirect back to files download after login

Posted: 23 Mar 2010, 09:40
by cwalters
Has a similar fix been made for PhocaGallery ? I have the same issue in Phoca Gallery where I have certain albums with "Registered" access that requires that a user must be logged in to view. After logging in, I would like the page to then redirect to the album/category that the user was trying to view. How do I resolve this issue ?

Re: Doesn't redirect back to files download after login

Posted: 29 Mar 2010, 18:55
by Jan
Hi, this is planned.

Jan

Re: Doesn't redirect back to files download after login

Posted: 28 Aug 2012, 18:31
by mjriding
I've come up with a solution to this that works for me. I did have to put some custom code in a couple places, but let me explain how it works and I'll also give you the code.

When the user clicks to download a file that is protected, they're asked to login. Once they login, they're taken back to the page they were originally on when they requested the file and then the file download is triggered.

There were three updates required to make this happen:

1. Update to the components/phoca_download/controller.php file. In this file, I store any file download requests into a session variable. If you put the code in the right spot, you can get all requests before the user is redirected to download. So, in controller.php right before the line:

defined( '_JEXEC' ) or die( 'Restricted access' );

I inserted:

$cuser = JFactory::getUser();
$session =& JFactory::getSession();

if(!$cuser->id) {
// no user is logged in
if ( strpos($_SERVER[REQUEST_URI],"download=") )
{
$session->set('filerequest', $_SERVER[REQUEST_URI]);
$session->set('returnpage', $_SERVER[HTTP_REFERER]);
}
}
else
{
$session->set("filerequest","");
$session->set("returnpage","");
}

Here I set two session variables if the user is not logged in. filerequest contains the URL directly to the file and returnpage contains the page the user was on when the request was made.

2. I had to update the Joomla core user controller in the com_user component: components/com_user/controllers/user.php. In that file, at around line 61 or so, there's a section labeled "perform the login" and then under that a section entitled "success". In the "success" section, I have the following code:

$app->setUserState('users.login.form.data', array());
$session =& JFactory::getSession();
$checkredirect=$session->get('returnpage');
if ($checkredirect>"")
{
$app->redirect($checkredirect);
}
else
{
$app->redirect(JRoute::_($app->getUserState('users.login.form.return'), false));
}

Notice I check to see if a redirect page was in the session. If so, I did the redirect with my own URL.

3. Steps 1 & 2 solve the problem of redirecting back to the original page after login. I wanted it do go one step further and fire off a download for the file they requested, so I created a custom module using a free tool like Jumi or Flexi Custom Code so I can create my own PHP code in the module. I published the module to a hidden position (make up any position you want) and it included this PHP code:

<?php
$session =& JFactory::getSession();
$ff=$session->get("filerequest");
$session->set("filerequest","");
$cuser = JFactory::getUser();
if (strpos($ff,"download=") && $cuser )
{
?>
<script type="text/javascript">
location.href="<? echo $ff; ?>";
</script>
<?
}
?>

All it does is check to see if a user is logged in. If they are, it grabs the file URL from the session and uses some javascript to redirect the browser to the download.

Now, I can already see the protests to this method, and I understand all of them. But, for me, this was the ONLY way I could get this to all work together. Someone with more time can go through and create a plugin that will do this as it's all pretty simple. I also had to put in a few checks/rechecks to make sure authentication wasn't broken, but overall, this should give anyone with this same problem some direction.
Put simply, I check the session