We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37510
    • 4 Posts
    Hi I just had a site built in Modx Revolution. Everything is finished and functions great. Since finalising the site the client has asked for a change to the secure login page. Intially it was developed so that staff could login and access secure information from one page, this works fine. But now they want to have the login page go to 3 separate secure pages with 3 separate different username/passwords from the one login page. I build the pages in the CMS but have no idea how to get them to work from the login.

    The developer I used has told me he cant do it so am trying to find a solution. Any help would be appreciated. Looking at the attachment it may be set up wrong, this is only the second site Ive setup with ModX the first dint have a secure login.

    See link and attachment for more details.
    http://www.vosfamilyoffice.com/6.html

    Thanks kiwi73
      • 3749
      • 24,544 Posts
      If I'm understanding you, one way to do that would be with a plugin attached to OnManagerLogin. At that point, the user has successfully logged in and is cleared for access to the Manager.

      The $user variable should be available there and you could use $user->get('username') to get the username and then use $modx->sendRedirect() to send the user to the appropriate page.
        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
        • 37510
        • 4 Posts
        I must tell you Im not a coder but a designer and can only get around fairly basic stuff.

        The login is for the front end user, so they dont need access to the Manager page, but I may not be understanding the procedure.

        On the login page In the Manager this is the code which is there now

        [[!Login? &loginTpl=`loginform` &loginResourceId=`7` ]]

          • 37510
          • 4 Posts
          !Login? &loginTpl=`loginform` &loginResourceId=`7`
            • 3749
            • 24,544 Posts
            In that case, to do it with a plugin you'd want OnWebLogin, rather than OnManagerLogin.

            But the simplest way to do it would be to have three separate login pages and tell the users to go to the appropriate one to log in. The other two would be duplicates of your existing Login page, but with the &loginResourceId value set to the ID of the page you want to send them to.

            To do it from a single Login page would require a plugin (or a postHook for the Login snippet -- the plugin would be slightly easier to code and a little more efficient). Just create a plugin called "Redirect Login" (or whatever, the name is arbitrary) with this code:
            <?php
            $userName = $user->get('username');
            
            /* specify the page the user will be sent to */
            switch ($userName) {
              case 'bob':
                  $page = 7;
                  break;
             
              case 'sally':
                  $page = 12;
                  break;
            
              case 'jim':
                  $page = 22;
                  break;
            
              /* anyone else */
              default:
                 $page = 99;
                 break;
            }
            
            /* send them there */
            $url = $modx->makeUrl($page, "", "", 'full');
            $modx->sendRedirect($url);
            


            Change the page IDs to the actual IDs of the pages you want to send them to (shown in parentheses after the name in the Resource tree in the Manager). Change the usernames to the actual usernames -- be sure to get the spelling right because they are case-sensitive.

            If you need to send more than one user to the same page, you can "stack" the case statements like this:

               
               case 'bob':
               case 'fred':
               case 'mary':
            
               page = 35;
               break;


            On the System Events tab of the plugin, check the box next to OnWebLogin and save the plugin.
              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
              • 37510
              • 4 Posts
              Thanks heaps for that BobRay!!!! its working fine now. Hopoefully theres no more changes from the client and this can be finalised. Thanks again, I really appreciate it.
              Kiwi73
                • 3749
                • 24,544 Posts
                I'm glad it worked for you. smiley
                  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