We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32525
    • 27 Posts
    Hi there, not posted here for a while as not had many problems with Revolution!

    I don’t think this is a bug, just me not getting it right, but I need help getting a login page working on a multi-domain website set up. Basically I have multiple contexts set up, each referring to a separate domain name and all of the works nicely. I also have set up the ACL and this too seems to be working.

    However I am now trying to simply set up a login page for users belonging to a user group to get to a separate section, but for the life of me, I can’t seem to get it to work.

    I have tried to track the error as it seems to be that the session data is not being set. The issue appears to occur at Line 127 of model/modx/processors/security/login.php:

    $rt = $modx->invokeEvent("OnWebAuthentication", $loginAttributes);


    $rt returns nothing, but I’m sure this should be setting the session.

    My login page is simply using [[!Login]], but it just loads the page without any errors etc or if I add a redirect url for logging in, then it works, but still has not user session, so the document page is not shown.

    I have also set up a simply snippet for testing the values after logging in, but no user data seems to be getting set in the $_SESSION:

    <?php
    $to_return = 'Context: ' . $modx->context->get('key');
    if ($modx->user->hasSessionContext($modx->context->get('key'))) {
      $to_return .= 'Logged in';
    } else {
      $to_return .= 'NOT logged in';
    }
    $to_return .= print_r($_SESSION, true);
    return $to_return;
    ?>


    The context is correct but the results of this after submitting the login form are:

    Array
    (
        [modx.user.contextTokens] => Array
            (
                [mycontext] => 3
            )
    
        [modx.user..attributes] => Array
            (
                [mycontext] => Array
                    (
                        [modAccessContext] => Array
                            (
                                [web] => Array
                                    (
                                        [0] => Array
                                            (
                                                [principal] => 0
                                                [authority] => 0
                                                [policy] => Array
                                                    (
                                                        [load] => 1
                                                    )
    
                                            )
    
                                    )
    
                            )
    
                        [modAccessResourceGroup] => Array
                            (
                                [3] => Array
                                    (
                                        [0] => Array
                                            (
                                                [principal] => 0
                                                [authority] => 0
                                                [policy] => Array
                                                    (
                                                        [load] => 1
                                                        [list] => 1
                                                        [view] => 1
                                                    )
    
                                            )
    
                                    )
    
                            )
    
                        [modAccessCategory] => Array
                            (
                            )
    
                    )
    
            )
    
        [mycontextDocgroups] => Array
            (
                [0] => 3
            )
    
        [modx.mycontext.session.cookie.lifetime] => 0
        [modx.request.referrer.redirected] => Array
            (
                [q] => user-login.html
                [username] => testuser
                [password] => testuser
                [returnUrl] => /user-login.html
                [service] => login
                [Login] => Login
                [PHPSESSID] => 4f5092ef59eabda931d37bbd8e29c8cb
            )
    
    )


    Any ideas? smiley
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I presume the [!Login]] is a typo; you actually are using [[!Login]]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32525
        • 27 Posts
        Quote from: sottwell at Sep 08, 2010, 12:12 AM

        I presume the [!Login]] is a typo; you actually are using [[!Login]]

        Oops, yes that was indeed a typo. I’ve updated the main post with the correct snippet call now - thanks for pointing this out!

        Update:

        I have also found that if I simply use $modx->user->hasSessionContext() rather than $modx->user->hasSessionContext($modx->context->get(’key’)), then the system thinks the user is logged in?!?
          • 32525
          • 27 Posts
          I think I have found my error, it appears that I should use this to check, rather than looking for the key:
          if ($modx->user->hasSessionContext($modx->context->get('value'))) {
          ...


          The next step is to work out why then I am still receiving a 404 page when logged in as a user with the correct privileges!
            • 50866
            • 3 Posts
            We have facing the same issue. We called the Login snippet as - [[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &loginResourceId =`1239` &logoutResourceId =`1238`]]

            when a web user fill the username and password and submit the login form the user redirect the page which assigned for loginResourceId i.e. 1239 but the page has not user session at all.

            We are not identify that either user is logged in or not.
            we tried all provided solutions over the various forums and blogs.
            Kindly help me to get the user session after login over the specify page.

            Is Login 1.9.0-pl working for modx 2.3.3?

            Thanks
            Praveen Shukla
              • 3749
              • 24,544 Posts
              If you have multiple front-end contexts, you need to add something like this to the Login tag:

              &contexts=`web,context2,context3`
                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
                • 50866
                • 3 Posts
                Hi Bob,

                Thanks for your reply but this is not working for me.
                We had done following steps to access the front end resources for specific users:
                1.Created a new resource group named as Client for web context.
                2.Created a new User group named as Agent which linked with Client Resource Group Load only Policy.
                3.Created a user and assigned User Agent group. Role is member.
                4.We also called the Login tag with &contexts=`web`.

                We are facing the same issue as before. We do not identify that why we are not getting user session after successful login.

                We can see the login count incremented after every login.

                If we added the Resource Groups to resource which coming after the login, we are getting page not found error.

                Kindly guide me for this.

                If you can suggest another way to achieve this, please let me know.



                [ed. note: praveen.shukla last edited this post 11 years, 2 months ago.]
                  • 37377
                  • 64 Posts
                  What happens if you give your user 'admin' permissions with access to all resource groups etc...?
                    • 3749
                    • 24,544 Posts
                    Make sure the user's User Group has a Context Access ACL entry for each front-end context. Just giving them access to the resources isn't enough.
                      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
                      • 50866
                      • 3 Posts
                      Hi Bob,

                      We added the user's User Group has a Context Access ACL entry as well as assign user to appropriate user group.
                      But still not able to create user session.

                      Thanks
                      Praveen Shukla