We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16501
    • 28 Posts
    Is it possible to use a preHook to set the loginResourceId value?

    I'm upgrading an Evo site that used WebLoginPE which had a call that directed users to a different page depending on their level of access.

    [!WebLoginPE? &loginFormTpl=`wlpeSymaraLogIn` &liHomeId=`54,38,69,15`!]


    I thought maybe I could do the same with a preHook snippet.
    eg.
    $hook->setValue('loginResourceId','3');


    Any help appreciated.

    This question has been answered by kwackyone. See the first response.

      • 3749
      • 24,544 Posts
      Login preHooks fire before the user is authenticated, so you can't redirect them there. I don't think that the the value set with $hook->setValue() will carry over to the main code where the user is redirected. I could be wrong.

      I'm assuming that you're upgrading to Revolution. It might be easier to use a plugin attached to OnWebLogin. The $user object is available there, the user has already been authenticated, and you can send the user anywhere you like. The login snippet properties would probably not be available there, though, so to get your list of resource IDs, you'd have to create a setting or make it a property of the plugin.

      This is off the top of my head, so it's probably wrong (it should work with either a System Setting, a User Setting, or a property of the plugin called liHomeId in a property set):

      $pages = $modx->getOption('liHomeId', $scriptProperties, array());
      $pages = explode(',', $pages);
      
      foreach ($pages as $page) {
         $doc = modx->getObject('modResource', (int) $page);
         if ($doc) {
             if ($doc->checkPolicy('view')) {
                 $url = $modx->makeUrl($page, "", "", "full");
                 $modx->sendRedirect($url);
             }
         }
      }
      return '';
      


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • Don't forget that Revo now has group-level settings.
          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
          • 3749
          • 24,544 Posts
          I'm not sure I trust them. wink
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • They were a bit buggy at first, but I'm pretty sure 2.3.3 got it all sorted out. At least I've had no problems with them.
              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
            • discuss.answer
              • 16501
              • 28 Posts
              Thank you so much for your replies and great ideas.

              I ended up with quite a simple solution based on both of your ideas.

              $page = $modx->getOption('liHomeId', $scriptProperties, array());
              $url = $modx->makeUrl($page, "", "", "full");
              $modx->sendRedirect($url);
              return '';


              Each group has the liHomeID setting specified and it works a treat.