We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26436
    • 19 Posts
    I have created a "network" of sites using contexts and a single installation of modx revolution. I would like my users to be able to login into any context and as such be logged into the entire network of sites (eliminating the need for users to re-login once they jump from one context to another. Based on what (little) I could find, it looks like some of this development has already been done, however, I am not getting results.

    Based on what I found in the Login snippet code (1.5.2) there are 3 different proprieties that relate directly to contexts: contexts, login_context and add_contexts. By adding these proprieties to my snippet call, I would assume that they would allow my users to be logged into multiple contexts after login, but it doesn’t look like it is working for me.

    to test this my code includes a reference to the logged in user [[+modx.user.username]] - a link to another context withing the site and finally the snippet call. After login, my reference user name appears, so I know I have successfully logged into the main site context. However after I follow the link to another context, my user reference [[+modx.user.username]] displays anonymous (not logged in).\

    Here is my snippet call: [[!Login? &loginTpl=`FormLogin` &errTpl=`FormLoginError` &loginResourceId=`1` &logoutResourceId=`1` &contexts=`contextb`]].

    Any help would be appreciated.
    Thanks
      • 26436
      • 19 Posts
      p.s. to clarify, the contexts I am referring to are set up as multiple subdomains across my site (site.com, siteb.site.com, sitec.site.com etc.)
        • 32098
        • 31 Posts
        Scott, I am going to get into trouble for asking this because I am breaking forum rules, but, heck, I can see you know the answer and I can’t resist the temptation of asking. The will is so weak.

        My problem is that I don’t know what the error template for Login is supposed to look like. You have one, and are clearly using it with some success. Can you share that template? I so, so want to have a peep at it. I have looked at the documentation for Login but there is no example given to see what placeholders need to be included in the chunk.

        Sorry I can’t help with your more advanced problem. I hope someone else can lend a hand.

        Thanks,

        Michael
          • 26436
          • 19 Posts
          Truth be told, that snippet is copied from the ClarityPack package available from modx. I simply copied the snippet call from one of its pages, and placed it into my site. (along with all the other clarity templates). Because it is publicly available i think it would be ok to post (if not someone will tell me and i will remove and apologize) so here it is.

          <p class="error"><strong>[[+msg]]</strong></p>

          That’s it, just the one line
            • 32098
            • 31 Posts
            Scott, thanks a lot for sharing that. I’m going to give it a try even though in the meantime I have set up my own (nasty looking procedural) login system for the front end because I was just getting noplace with Login. The documentation was just too patchy for a guy of my few talents (and stragely patchier than the documentation for the register snippet included with Login, which even has an example complete with error template chunk).

            Thanks again.

            Hope you manage to sort your problem out.
              • 29024
              • 1 Posts
              I have the same problem as scott.

              Logging in via the login snippet is possible only in the default web context. In every other context, the same login form logs me nowhere. It just refreshes the login page doing nothing.

              When I successfully log into the "web" context, and change the context to another context, I have the access to the logged in users name (via the MODx-es "logged in user" placeholder), so everything seems to be ok, but as soon as I try to access the context’s native profile management page, It gives me an "Unauthorized error".

              I’ve been trying out different access rights scenarios for the non-default context with no results.

              I’ve also filled out the &contexts setting with the contexts I want to be logged into via the Login snippet but that doesn’t help either.

              Except the login part, contexts work ok.

              I’ve created different contexts (for different languages) following a tutorial on doing that. I’ve created a gateway script that properly switches contexts (I’m sure my problem has got nothing to do with context switching as suggested in a post regarding a similar problem). I’ve edited the rewrite rules on apache so the pages get served correctly.

              I hope there is an elegant solution to this. One that I’ve been overlooking all this time.
                • 29796
                • 91 Posts
                i have same problem .. anyone know the solution ? .. i allready posted my problem on this post http://modxcms.com/forums/index.php/topic,57908.msg364401.html#msg364401
                • Are your contexts using different domains / sub-domains? You might try adding a session_cookie_domain setting.
                    www.darkstardesign.com

                    Are you in the Nashville area? Join us for our next MODX meetup!
                  • I seriously apologize for being so late to this thread, I would never have seen it - if not for Google.

                    It seems to me, the implementation utilized here may have been the hard one.

                    Contexts are isolated entities and are typically used autonomously.

                    It may have been much simpler to:

                    • Create one Context to create the entire site and the "so called" subdomains.
                    • Use a control panel (or directly adding redirects to .htaccess) to bounce the visitor to top level categories (even lower is possible) based on the sub.domain.

                    In essence, if you need a user to have access across all Contexts, it may have been better to not use Contexts in the first place.

                    If you actually want them to have access to a group of sites and be logged into them all, you could always have a Snippet called to make sure all authenticated users have the correct Contexts listed in their $_SESSION, by first grabbing a list of available Context Names available in your MODX installation, removing the "mgr" and injecting the rest via the API.

                    I believe you can also, create a similar Snippet which outputs a comma delimited string and call Login with:

                    &contexts=`[[getAllContexts]]`


                    If your Snippet writing skills are not up to the task, then cheat and create a Chunk with the list of Contexts as they are added to the site and change the call to:

                    &contexts=`[[$getAllContexts]]`


                    With the Context Names in the Chunk as Context1,Context2,Context3....

                    I believe you could always place your list in the Login call....
                    &contexts=`Context1,Context2,Context3`


                    These ideas are off the top of my head, but should be feasible.





                      Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

                      Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
                      • 45766
                      • 78 Posts
                      Solution for your Problem?

                      Had the same Problem (but one domain instead of different Domains). Login for default context works fine. The second not:

                      • Nothing happened after Login
                      • Backend says user is logged in
                      • for example [[+modx.user.id]] stays empty

                      Setup

                      • 2 Contexts with Babel
                      • gateway to switch contexts
                      • Login extra

                      Solution which works fine (but only after i made all the 3 changes and cleared the cache via ftp)

                      • Add 2 lines of code at the gateway to initialize BOTH contexts (see code at the bottom)
                      • Change System Setting: session_cookie_domain: myDomain.de || session_cookie_path: /
                      • Add Parameter &contexts=`web-ja,web` to [[!Login]] call

                      gateway
                      <?php
                      // 2 lines of code to initialize the contexts
                      $modx->initialize('web');
                      $modx->initialize('web-ja');
                      
                      if($modx->context->get('key') != "mgr"){
                          /* grab the current langauge from the cultureKey request var */
                          switch ($_REQUEST['cultureKey']) {
                              case 'de':
                                  /* switch the context */
                                  $modx->switchContext('web');
                                  break;
                              case 'ja':
                                  /* switch the context */
                                  $modx->switchContext('web-ja');
                                  break;
                             	default:
                                  /* Set the default context here */
                                  $modx->switchContext('web');
                                  break;
                          }
                          /* unset GET var to avoid
                           * appending cultureKey=xy to URLs by other components */
                          unset($_GET['cultureKey']);
                      }
                      


                      login call
                      
                      [[!Login?
                        &loginTpl=`lgnLoginTpl`
                        &logoutTpl=`lgnLogoutTpl`
                        &errTpl=`lgnErrTpl`
                        &loginResourceId=`[[++login_memberPage]]`
                        &logoutResourceId=`[[*id]]`
                        &contexts=`web-ja,web`
                      ]]