Passing $_GET variables through Login

Permalink 2 users found helpful
I swear I have seen this asked before, but couldn't find it anywhere..
Is there a simple way of passing GET variables through the login? IE, user clicks restricte link:www.www.website.com/members/award?aID=1234....

C5 detects a login is required

User logs in successfully

C5 redirects user to /members/award page with the aID variable still intact?

Thanks,

Guy

guythomas
 
guythomas replied on at Permalink Reply
guythomas
Okay,


It didn't take me long to perform the modifications required to gain this functionality.

You will need to override your login.php controller and singlepage.

In the Single Page I just looked for the bit of code that said:

<?php  $rcID = isset($_REQUEST['rcID']) ? Loader::helper('text')->entities($_REQUEST['rcID']) : $rcID; ?>
   <input type="hidden" name="rcID" value="<?php echo $rcID?>" />


and appended the following right after it:

<?php foreach ($_GET as $key=>$variable){?>
   <input type="hidden" name="get[<?php echo $key?>]" value="<?php echo $variable?>" />
   <?php } ?>


This adds any$_GET variables as hidden $_POST variables to the do_login function

In the Controller I looked for:

//set redirect url
      if ($nh->integer($rcID)) {
         $nh = Loader::helper('navigation');
         $rc = Page::getByID($rcID);
         $url = $nh->getLinkToCollection($rc, true);
         $loginData['redirectURL'] = $url;   
      }elseif( strlen($rcID) ){
         $rcID = trim($rcID, '/');
         $nc2 = Page::getByPath('/' . $rcID);
         if (is_object($nc2) && !$nc2->isError()) {
            $loginData['redirectURL'] = BASE_URL . DIR_REL . '/' . DISPATCHER_FILENAME . '/' . $rcID;
         }
      }


This is where the redirect url is set. I simply pulled the post vars back out and appended them again as get vars like so:


//set redirect url
      if ($nh->integer($rcID)) {
         $nh = Loader::helper('navigation');
         $rc = Page::getByID($rcID);
         $url = $nh->getLinkToCollection($rc, true);
         if ($_POST['get']){
         $url .= "?";
         foreach ($_POST['get'] as $key=>$var){
         $url .="$key=$var&";
            }
         }
         $loginData['redirectURL'] = $url;   
      }elseif( strlen($rcID) ){
         $rcID = trim($rcID, '/');
         $nc2 = Page::getByPath('/' . $rcID);



Of course, I just came up with this in 5 minutes, and your results may vary..

-Guy
JonRimmer replied on at Permalink Reply
JonRimmer
Hi There
Can you tell me in is possible in C5.8 when someone click login link on certain page of a site they can be redirected back to that page after they have logged in. It wont be the same page every time i.e. someone login on page A or B and they are redirected to which ever page they where on before logging in. Hope that makes sense.

Thanks for you help
JohntheFish replied on at Permalink Reply
JohntheFish
Not a standard option at
dashboard/system/registration/postlogin

It was certainly possible to code this on legacy 5.6 (further examples in forums).
https://www.concrete5.org/community/forums/customizing_c5/page-redir...

There is also a redirect managing addon that may help
https://www.concrete5.org/marketplace/addons/afixia-login-redirects...
JonRimmer replied on at Permalink Reply
JonRimmer
Hi John
Thanks for the comments. I did contact the Afixia addon guy but he told me the addon doesnt do what I need unfortunately.

If I could get this function developed I would, if you or if you know of someone who could do this for me that would be great

Thanks
J