We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36818
    • 119 Posts
    I have to setup two separate logins on the same page.

    Is there a way to define the following scenario:


    • 2 Login forms
    • 2 users
    • 2 Landing pages
    • 2 Logout pages

    The goal is to achieve that User1 can login on Login 1 and User2 on Login2. But that login is denied when User1 tries to login on Login2 (and vice versa).

    Is there a way to it?

    I know there is the possibility to redirect users according to their usergroups or/and usernames (Thread http://forums.modx.com/thread/?thread=72130&page=1). But this is a feasible solution.

    Thanks for your help.

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

    • discuss.answer
      • 4172
      • 5,888 Posts
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36818
        • 119 Posts
        Thank you, Bruno,

        it is not exactly what I was looking for, but it will help as a workaround.

        If someone else could be interested in how I made it:
        Modal Login form -> Jquery Ajax call --> Resource with Snippet Call --> Snippet: executes Login (return success or error) --> Ajax redirects to resource --> Resources dispatches with Extra redirectusergroups

        Btw Bruno: i didn't found your Extra in the package management...
          • 3749
          • 24,544 Posts
          You could put a snippet at the top of the landing pages with code like this:

          $id = $modx->user->get('id');
          if ($id != 12) {
             return 'Sorry, you're not allowed to see this page';
          }


          You'd change 12 to the ID of the user who was not authorized on each page.

          You could also just redirect unauthorized users back to the login page:

          $id = $modx->user->get('id');
          if ($id != 12) {
             $url = $modx->makeUrl(22, "", "", "full"); // change 22 to the ID of the login page
             $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
            • 36818
            • 119 Posts
            Thank you Bob,

            This I a nice solution, but unfortunately not for my case, because after login I do not show menu entries for the logged in users, but only redirect it to a corresponding page. So the use of Bruno's script is the workaround I can use.

            What I had in mind was a Login-Extra that had a setting for user groups (or users) to check against. I.e. it would show the login form or the "logged in" depending on that check. So it would be possible to run to completely separated login structures on one page.
            Could the Login Extra be expanded by that functionality? Just out of interest.

            Best regards
            fabian

            Quote from: BobRay at Sep 17, 2015, 08:09 PM
            You could put a snippet at the top of the landing pages with code like this:

            $id = $modx->user->get('id');
            if ($id != 12) {
               return 'Sorry, you're not allowed to see this page';
            }


            You'd change 12 to the ID of the user who was not authorized on each page.

            You could also just redirect unauthorized users back to the login page:

            $id = $modx->user->get('id');
            if ($id != 12) {
               $url = $modx->makeUrl(22, "", "", "full"); // change 22 to the ID of the login page
               $modx->sendRedirect($url);
               return '';
            }




              • 3749
              • 24,544 Posts
              I'm afraid I don't understand your comment. My method doesn't involve menus at all. It just makes sure people can't go to the wrong page.

              The problem is that Login has no submission key that would allow it to be used twice on the same page. Even if you have separate &loginResourceId properties in your two Login tags, all users will be sent to the first one because that login tag will always execute first.

              If you're not satisfied with redirectUserGroups, you could easily have just one Login form and use a Login postHook to send the users to their appropriate page. Adding my snippets would make sure that neither user could access the other page directly. The redirectUserGroups extra won't prevent them from going directly to the other user's page if they can figure out the url.

              If you're determined to have two forms, I think you could use JavaScript fired by onSubmit() in the two buttons that would run a processor to log the user in and forward them to the right page, but you'd still need my code, or the permissions system, to make sure they couldn't access the unauthorized page directly.
                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
                • 36818
                • 119 Posts
                Sorry, Bob,

                You're absolutely right.
                I was just wondering what it would need to acheive the functionality to completely separate two logins on one page. And you answered it: Login would need a submission key.
                  • 3749
                  • 24,544 Posts
                  I think it would be easy to add, though the Login code it a bit labyrinthine. Maybe someday I'll submit a pull request.
                    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
                  • If you're trying to show something different depending on the user group, Personalize might be what you're looking for: http://modx.com/extras/package/personalize

                    I'm still confused why you need two different login forms though. Why can't they both use the same login form? Or is one person supposed to login twice?
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 36818
                      • 119 Posts
                      Thanks for this hint, Mark,

                      Why to different logins?
                      A comany has a website with to products (p1 and p2). Each of the products have a menu-tree and a "login/download" section (and therefore a separate login form).

                      Now I can use Login with two different logins (users u1 and u2) to decide if a customer can login to the respective login-section or not.

                      But: if u1 is logging in on p1, then the login form on p2 also has the status "logged in". With the Extra from redirectusergroups and/or the snippet from Bob it is possible to direct the user to the "right" landing page and avoid that he sees the download page not meant for him.
                      But it is not possible to split it completely, i.e. u1 logs in for p1, and the login form for p2 still shows the login form.

                      Hope I could clarify me idea.

                      Quote from: markh at Sep 20, 2015, 07:44 AM
                      If you're trying to show something different depending on the user group, Personalize might be what you're looking for: http://modx.com/extras/package/personalize

                      I'm still confused why you need two different login forms though. Why can't they both use the same login form? Or is one person supposed to login twice?