We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16085
    • 203 Posts
    knightknight Reply #1, 15 years ago
    MODX Revolution 2.1.3-pl
    login-1.6.5-pl

    Is it possible to use Login-1.6.5-pl &postHooks to pull from the users extended field {"redirect":9} and automatically redirect them on login. Without have to use a snippet redirect on a blank resource.

    My lack of php skills are lack some what in how to extract the 9 form the array or even if &postHooks is the right one to use.

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

    • discuss.answer
      • 28215
      • 4,149 Posts
      splittingred Reply #2, 15 years ago
      Yes, use a postHook:

      $profile = $modx->user->getOne('Profile');
      if ($profile) {
        $extended = $profile->get('extended');
        if (!empty($extended['redirect'])) {
          $url = $modx->makeUrl($extended['redirect'],'','','full');
          $modx->sendRedirect($url);
        }
      }
      return true;
      
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 16085
        • 203 Posts
        knightknight Reply #3, 15 years ago
        Thanks splittingred, works perfectly. I knew what I wanted to achieve, be it quite simple, just didn't know the right code. Thanks again!! smiley
          • 27704
          • 21 Posts
          Hello! I'm facing the same problem and was happy to find this here, but until now I don't get it to work.

          I have a MODx 2.26 installation with different contexts for different domains.

          To my user I gave an attribute called userLoginPage, where the ID of the user's start page is declared. The user has access to this document. In the start page of my web-context I give a call to the Login 1.7.3 and I created a snippet like above (->splittingred) called UserLoginPage for the &postHooks of the Login-call.

          Snippet call:
          [[!Login? &postHooks=`UserLoginPage` ]]

          UserLoginPage-Snippet
          <?php
          $profile = $modx->user->getOne('Profile');
          if ($profile) {
            $extended = $profile->get('extended');
            if (!empty($extended['userLoginPage'])) {
              $url = $modx->makeUrl($extended['userLoginPage'],'','','full');
              $modx->sendRedirect($url);
            }
          }
          return true;


          What happens after click on the Login-button? I'm logged in, but the page shown to me is the same page where the login-form was sent. No redirect sad


          What am I doing wrong?

          Are there any problems known about Login 1.7.3 working with multidomain structures?

          Thanx for help!
            • 23050
            • 1,842 Posts
            Hello,

            Thanks splittingred for your snippet ! It works... but only when I log out laugh When I log in, I'm redirected to &loginResourceId but not to &postHooks=`redirectPagePerso` where redirectPagePerso is your code :

            $profile = $modx->user->getOne('Profile');
            if ($profile) {
              $extended = $profile->get('extended');
              if (!empty($extended['pagePerso'])) {
                $url = $modx->makeUrl($extended['pagePerso'],'','','full');
                $modx->sendRedirect($url);
              }
            }
            return true;


            Login call :
            [[!Login? &loginTpl=`lgnLoginTplBC` &postHooks=`redirectPagePerso` &loginResourceId=`11`]]


            If I don't use &loginResourceId, I'm staying on login page

            Login 1.8.0
            MODx Revo 2.2.4-pl

            Thank you !