We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16633
    • 116 Posts
    Hi,

    I am setting up a secure section on my website in Revo 2.0.6 pl2, I have 2 user groups and 2 users (these 2 are for testing there will be multiple users in future). Each user group has access to different resources. So when a user logs in I need them to get redirected to the resource that they have access to.

    In Evo I see that you could specify multiple resource ids to redirect to and it would take you to the resource that you have access to. Is there a way to do this in Revolution? I tried:

    [[!Login? &loginResourceId=`38,39` &logoutResourceId=`37`]]

    But it did not work.
      --
      Landon Poburan
      Web Designer and Developer

      http://www.categorycode.ca
      http://www.landonp.com
      • 3749
      • 24,544 Posts
      I don’t think that’s been implemented in the login snippet, but it’s a good feature request. wink

      http://bugs.modx.com/projects/login
        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
        • 4172
        • 5,888 Posts
        I think you can use a posthook with

        <?php
        $redirs['groupA']='38';
        $redirs['groupB']='39';
        
        foreach ($redirs as $group => $id){
            if ($modx->user->isMember($group)){
                $url=$modx->makeUrl($id);
                $modx->sendRedirect($url);
            }
        }
        return true;
        
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 16633
          • 116 Posts
          I have created this snippet

          <?php
          /*
           * @file    LoginPostHook.php
           */
          
          $redirs['Producers']            = '38';
          $redirs['Board of Directors']   = '39';
          
          foreach ($redirs as $group => $id){
              if ($modx->user->isMember($group)){
                  $url=$modx->makeUrl($id);
                  $modx->sendRedirect($url);
              }
          }
          
          return true;
          ?>
          


          and here is my Login call

          [[!Login? &postHooks=`LoginPostHook` &loginResourceId=`` &logoutResourceId=`37`]]
          


          Doesn’t seem to work.
            --
            Landon Poburan
            Web Designer and Developer

            http://www.categorycode.ca
            http://www.landonp.com
            • 4172
            • 5,888 Posts
            ok, you’re right. This solution seems not to work correctly.
            Only on logout I was redirected to that pages.
            Another solution which seems to work:

            Create a new resource: loginredirect (lets say resource-id 999)
            put this snippet
            [[!LoginPostHook]]

            to that resource and use the id of that resource like this in your login-call.
            &loginResourceId=`999`
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 16633
              • 116 Posts
              That totally worked but they really need to build a better solution to this for Login.
                --
                Landon Poburan
                Web Designer and Developer

                http://www.categorycode.ca
                http://www.landonp.com
                • 4172
                • 5,888 Posts
                you can now also use this snippet to redirect usergroups:
                http://modxcms.com/extras/package/?package=794
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 36704
                  • 131 Posts
                  Hi Bruno,

                  How can i use this redirectUsergroups?
                  do i need to insert this on resource id [[!redirectUsergroups? &redirs=`Members:3,adminpage:8`]]?

                  Please let me know how to use it properly.

                  Thanks,
                  Larry Sabini
                    • 15075
                    • 6 Posts
                    Maybe too late, but for those solving user redirect on login, this is working postHook for me:
                    <?php
                    if($_REQUEST['service']=='login'){
                    $redirs['group1'] = '11';
                    $redirs['group2'] = '23';
                    
                    $user = $modx->getObject('modUser', array('username' => $hook->getValue('username')));
                    
                    foreach ($redirs as $group => $id){
                        if ($user->isMember($group)){
                            $url=$modx->makeUrl($id);
                            $modx->sendRedirect($url);
                        }
                    }
                    }
                    return true;
                    


                    You cannot use $modx->user to get the user just logged in (as stated in Login docs), but you can use username from login form. This posthook fires after user is already authenticated, so I consider using username directly as safe method.
                    Also, I have added check if this is login or logout request, otherwise this postHook would fire with logout as well.
                    There should be some other checks for $user validity and some nicer way to specify redirs array as snippet parameter, but as a starting point this should work.