We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38553
    • 12 Posts
    medienzentrale Reply #1, 10 years ago
    I am using isLoggedIn Script for a members only site. It seems to work nearly perfect besides one thing: I am using the normal Chunk (lgnLoginTpl) which comes with the complete Login package. There in the form an action with an url/domain etc. is needed but i need it dynamic. This means if you enter an protected page you are redirected to login and after logging in back to protected page. I have more than one protected page so it must be some kind of "intelligent". &redirectToPrior=1 is also not working in this case.

    Can anybody help and tell me how to set up lgnLoginTpl correctly to get isLoggedIn script to work as I need?
      • 38553
      • 12 Posts
      medienzentrale Reply #2, 10 years ago
      Maybe it's better to post the login chunk.
      I think the problem is the post in following line:
      <form class="loginLoginForm" action="[[++site_url]][[~[[*id]]]]" method="post">

      How to modify this so that the user is redirected to the page where he's coming from?


      <div class="loginForm">
          <div class="loginMessage">[[+errors]]</div>
          <div class="loginLogin">
               <form class="loginLoginForm" action="[[++site_url]][[~[[*id]]]]" method="post">
                  <fieldset class="loginLoginFieldset">
                      <legend class="loginLegend">[[+actionMsg]]</legend>
                      <label class="loginUsernameLabel">[[%login.username]]
                          <input class="loginUsername" type="text" name="username" />
                      </label>
                      
                      <label class="loginPasswordLabel">[[%login.password]]
                          <input class="loginPassword" type="password" name="password" />
                      </label>
                      <input class="returnUrl" type="hidden" name="returnUrl" value="[[+request_uri]]" />
      
                      [[+login.recaptcha_html]]
                      
                      <input class="loginLoginValue" type="hidden" name="service" value="login" />
                      <span class="loginLoginButton"><input type="submit" name="Login" value="[[+actionMsg]]" /></span>
                  </fieldset>
              </form>
          </div>
      </div>
        • 38553
        • 12 Posts
        medienzentrale Reply #3, 10 years ago
        I tried some things and I now it seems I have only one problem which is that I am redirected to unauthorized page (login page), that works fine but after logging in I am not redirected to the right protected page.

        I made to different pages test1 and test2. If I am loggin in I am always redirected to test1.

        test1 login -> test1

        test2 login -> test1

        It seems &redirectToPrior=1 is overriden by &loginResourceId=12. I am calling the plugin with following code:

        [[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &logoutResourceId=`0` &loginResourceId=`12` &redirectToPrior=`1`]]


        Removing &loginResourceId=12 (ID 12 is test1) doesn't work at all and redirects my to my 404 page (home). &loginResourceId=12 should be removed but what to insert instead?
          • 3749
          • 24,544 Posts
          In some cases, redirectToPrior doesn't work if you entered the address to the "prior" page manually. It works for me if you get to the page via a link. Looking at the code, it appears that you're correct about having to leave out &loginResourceId. If it's set, it will always be used, though it seems to me that having &redirectToPrior override it would make more sense.

          I think that would be accomplished by changing line 329 of the Login snippet from this:

          $loginResourceId = $this->getProperty('loginResourceId',$redirectBack);


          to this:

          $loginResourceId = empty($redirectBack)? $this->getProperty('loginResourceId','') : $redirectBack;


          If you want to make the change, I'd duplicate the Login snippet as MyLogin, make the changes there, and use MyLogin in your tag, so the change would survive upgrades. [ed. note: BobRay last edited this post 10 years ago.]
            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
            • 38553
            • 12 Posts
            medienzentrale Reply #5, 10 years ago
            Thank you for your help.
            It doesn't seem to work. After changing line 329 I am redirected to home site (my 404 site) .

            This is my call for login:
            [[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &logoutResourceId=`0` &redirectToPrior=`1`]]


            This is the changed line 329 as you mentioned it:
            $loginResourceId = empty($redirectBack)? $this->getProperty('loginResourceId','') : $redirectBack;


            Does anybody know where's the mistake?
              • 3749
              • 24,544 Posts
              Try deleting all files in the core/cache directory and clearing the browser cache to make sure your change takes effect. Also, make sure you're changing the Login snippet in the Manager, not the file.
                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
                • 38553
                • 12 Posts
                medienzentrale Reply #7, 10 years ago
                I tried all you mentioned but it still redirects to to my 404 page:
                - made an new core/cache directory
                - cleared browser cache (and used another browser)
                - made the changes in MODX and not in an editor.
                I modified following file: core/components/login/controllers/web/Login.php. Is this the right file?

                After redirecting to 404 site the adress from the login page is still shown in browser's adress field.
                  • 3749
                  • 24,544 Posts
                  Possibly I misread the code (it wouldn't be the first time).

                  Are you sure that the logged-in user really has access to the protected page? You need to test from a browser where you're not logged in to the Manager to make sure.
                    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
                    • 38553
                    • 12 Posts
                    medienzentrale Reply #9, 10 years ago
                    I can't get it to work. I am short before giving up.
                    Now I can't log into frontend anymore. User Management of MODX is way too complicated.

                    Maybe there's another way to achieve what I need.
                    I need a protected page (gallery). There are different users which are only allowed to see their own gallery. I think think there needn't bee different usergroups because the urls are only given to that users.
                    User visits the given URL. If not logged it he is redirected to login screen. After logging in he is redirected to his gallery.

                    Is there some kind of a simple solution?
                      • 3749
                      • 24,544 Posts
                      Yes, I think what you may be looking for is a Login postHook. If you name the users' galleries based on their username or ID (I would do this in the alias), you can use $modx->sendRedirect() in the postHook to send them to their gallery's main page. That way you don't need &redirectToPrior or &loginResourceID.

                      In the gallery template, you can use a snippet to redirect anyone who is not logged in or who is not on his or her own page to the Login page, also using $modx->sendRedirect().

                      With those two options, you don't need to use the MODX permissions system.

                      The snippet on the gallery pages would look something like this (untested):

                      <?php
                      $loginPageId = 12;  /* set to ID of Login Page */
                      $url = $modx->makeUrl($loginPageId, "", "", "full");
                      
                      if ($modx->userHasSessionContext('web') 
                         && $modx->user->get('id') == $modx->resource->get('alias') ) {
                          return '';
                      }
                      $modx->sendRedirect($url);
                      
                      


                      I used the ID because the username might contain characters that would be illegal for a URL.
                        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