We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27408
    • 33 Posts
    Say John Doe requests page http://siteurl/index.php?id=77, but John forgot to log in, so that page is locked for him. He gets an error page. John logs in to get to the page, but gets redirected to the mainpage.

    This is annoying for users. And even when specifying liHomeId in the WebloginPE snippet call it won’t work. The url in the browser will show the url requested, but liHomeId will be equal to the error page ID, as will [*id*]. How do we fix this?

    There is a quick and dirty way to fix this, we have to ’hack’ WebloginPE a little bit.

    -Open the WebloginPE snippet
    -Find
    $loHomeId = isset($loHomeId) ? $loHomeId : '';

    -On the row above it add the following code:
        $liHomeId = $modx->stripTags($modx->db->escape($_GET['id']));

    This will get the id used in the url, and when the user logs in will send him right back to the page he requested. (It will also strip HTML and MODx tags and escape SQL for some basic security)

    This may not be the ideal solution for this problem, and I would not advise to use it in live productions. There was 15 minutes of thinking invested in it so it could be done way better and more secure then right now. I just thought to share this so people have a workaround for this problem.
      • 12808
      • 70 Posts
      Is this only way to achieve redirection to last visited page after successful login?

        --
        www.spotkg.com
      • You could use a plugin, the OnPageUnauthorized event will have the id of the attempted resource in the $_REQUEST array as $_REQUEST[’refurl’]. You could load this into the SESSION, then use another event OnWebLogin to load it back into $_REQUEST[’refurl’].
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 12808
          • 70 Posts
          Thanx sottwell,
          Your solution gave me an idea how to resolve my problem:

          I’m not restricting whole pages to regular visitors, but, only a parts of page (with slightly modified Personalize snippet), so when visitor visits page with restricted data, first of all, I’m calling snippet:

              $idDoc = $modx->documentIdentifier;
              $wholeURL = $modx->makeUrl($idDoc);
              $wholeURL = 'http://www.mydomain.com' . $wholeURL;
              $_SESSION['lastURL'] = $ceoURL;
          


          and asking user to login.

          If user is successfully logged in, the following plugin is triggered (with OnWebLogin event only):

          $eventName = $modx->event->name;  
          switch($eventName) {  
               case 'OnWebLogin': 
                    if ($_SESSION['lastURL'] !== '') {
                              $redirect = $_SESSION['lastURL'];
                              $_SESSION['lastURL'] = '';
                              $modx->sendRedirect($redirect);
                    }
                   break;
           } 
          


          I’m not a php expert, I’m sure that code could be better, but, everything working fine smiley
          Hope that someone will find this useful.

          With regards,
          Ivan
            --
            www.spotkg.com