We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31640
    • 100 Posts
    I have the login snippet up and running and it is working in the 2 languages.

    I am working with 2 contexts: web & it
    so the websites are
    www.site.com/
    and
    www.site.com/it/

    The user can do a login in both languages.

    But i still have 1 major issue:
    - The personalise snippet doesn't work in the 'it' context despite i have added the following
    &contexts=`web,it`
    to my login snippet

    also

    I need to fill in the logged in user as a field in a custom table and i am using the value of
    $modx->getLoginUserName()
    but this gives me null in the IT context.

    Please can somebody help, because this is one of the last issues before this site can go live... [ed. note: visvoer last edited this post 11 years, 5 months ago.]
      • 3749
      • 24,544 Posts
      Try one of these:

      $modx->getLoginUserName('it');
      $modx->getLoginUserName('web');
      
      $modx->user->get('username');


      For the first two, you could try both and use whichever one comes up !empty.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 31640
        • 100 Posts
        Bob,

        this solves the issue for getting the value into the database....

        The first issue is a bigger issue. I investigated a little further a these are my findings.
        All works well in the web context. It goes wrong in the 'it' context.

        I have babel installed. So in every context i have a version of the login snippet. These are the login calls:

        web context
        [[!Login? 
        &loginTpl=`loginTpl`
        &logoutTpl=`logoutTpl` 
        &errTpl=`lgnErrTpl` 
        &logoutResourceId=`1`
        &loginResourceId=`13` 
        &redirectToPrior=`1`
        &contexts=`web,it`]]


        it context
        [[!Login? 
        &loginTpl=`loginTpl` 
        &logoutTpl=`logoutTpl` 
        &errTpl=`lgnErrTpl` 
        &logoutResourceId=`16`
        &loginResourceId=`23` 
        &redirectToPrior=`16`
        &contexts=`it`]]


        In the it context it does the redirect but the user object stays empty !!
        The command
        $modx->user->hasSessionContext('it')
        also returns nothing.
        That is why my personalise snippet is not working. Also my 'it' pages are not protected with an ACL at this point.. this is something i urgently need to get working...

        When i add the web context parameter to the it version of the login snippet things starting to get ugly.
        When i use my website then, after doing the login the website no longer gets redirected but gives me an 503 Error - Page not found
        And in the server log i see
        (ERROR @ /index.php) Could not load context: it


        I also noticed that when i am logged in, in the web context and i click a link from the italian context, for example the home page (unprotected page)
        the page doesn't want to go there and gives me an error instead:
        (ERROR @ /index.php) Could not load context: it


        I am using version 1.8.0 of the login snippet

        Maybe this can also help. This is my plugin to handle the switching of the language
        if($modx->context->get('key') != "mgr"){
            /* grab the current langauge from the cultureKey request var */
            switch ($_REQUEST['cultureKey']) {
                case 'it':
                    /* switch the context */
                    $modx->switchContext('it');
                    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']);
        }
        
          • 3749
          • 24,544 Posts
          I don't know why that would happen. You might try this somewhere:

          $modx->reloadContext('it');



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 39932
            • 483 Posts
            @visvoer:

            Have you considered just making your Login Snippet login to all front-end Contexts in every front-end Login?

            When i use my website then, after doing the login the website no longer gets redirected but gives me an 503 Error - Page not found

            This 503 error only ever occurs with me when I have the System Setting "allow_forward_across_contexts" set to "No".
              Website: Extended Dialog Development Blog: on Extended Dialog
              Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
              Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

              Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
              • 31640
              • 100 Posts
              Guys,

              Thanks for the reply but both suggestions did not solve my issue...

              Putting the allow_forward_across_contexts to No hgas fixed the 503 error page so this is an improvement. I also added in both contexts a specific error page to see if he redirects to this page for an unknown reason...

              I have added some logging to the plugin:
              if($modx->context->get('key') != "mgr"){
                  /* grab the current langauge from the cultureKey request var */
              				$modx->log(modX::LOG_LEVEL_ERROR, 'CLUTURE:' .$_REQUEST['cultureKey']);
                  switch ($_REQUEST['cultureKey']) {
                      case 'it':
                          /* switch the context */
              						$modx->log(modX::LOG_LEVEL_ERROR, 'SWITCH START');
                          $modx->switchContext('it');
              						$modx->log(modX::LOG_LEVEL_ERROR, 'SWITCH STOP');
                          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']);
              }
              

              Added the context to the login snippet in the IT context
              [[!Login? 
              &loginTpl=`loginTpl` 
              &logoutTpl=`logoutTpl` 
              &errTpl=`lgnErrTpl` 
              &logoutResourceId=`16`
              &loginResourceId=`23` 
              &redirectToPrior=`16`
              &contexts=`web,it`]]
              


              Now i am having a very bizar situation. When a user does a login in the IT context.
              Both context are logged in so this is working fine. Both are giving 1. So i am correctly logged in
              $modx->user->hasSessionContext('web');
              $modx->user->hasSessionContext('it');
              

              But on the website i am redirected to the error page in the web context
              but in the URL in the browser i see the correct url that i was supposed to see.
              In the log i see the following error
              [2012-09-20 13:30:11] (ERROR @ /index.php) CULTURE:it
              [2012-09-20 13:30:11] (ERROR @ /index.php) SWITCH START
              [2012-09-20 13:30:11] (ERROR @ /index.php) SWITCH STOP
              [2012-09-20 13:30:11] (ERROR @ /index.php) CULTURE:it
              [2012-09-20 13:30:11] (ERROR @ /index.php) SWITCH START
              [2012-09-20 13:30:11] (ERROR @ /index.php) Could not load context: it
              [2012-09-20 13:30:11] (ERROR @ /index.php) SWITCH STOP
              [2012-09-20 13:30:12] (ERROR @ /index.php) Could not load context: web
              [2012-09-20 13:30:12] (ERROR @ /index.php) Could not load context: it
              


              So there is still something wrong...

              Any ideas?
                • 39932
                • 483 Posts
                I don't know how to parse those errors or what they mean. sad Perhaps, BobRay, Sottwell or one of the other gurus or devs know?
                  Website: Extended Dialog Development Blog: on Extended Dialog
                  Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                  Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                  Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                  • 3749
                  • 24,544 Posts
                  It kind of looks like an error is sending you to the error page over and over. That might happen if an anonymous user did not have access to the context they are being sent to. The switchContext('it') fails, but the user is forwarded to a page in that context, which fails, throwing them back to the error page.

                  Does a user who is not logged in have Context Access ACL entries giving them access to both Contexts? (IOW, the Anonymous user group)?


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    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
                    • 31640
                    • 100 Posts
                    Found the issue...
                    When i did the register, the newly added users are added to the customers user group but this group didn't had access to both contexts

                    Super thanks for all your help...
                      • 31640
                      • 100 Posts
                      It looks like it is not solved sad
                      i am not getting it anymore...

                      So i have 2 contexts.
                      In the web context i have the following

                      [[!Login? 
                      &loginTpl=`loginTpl`
                      &logoutTpl=`logoutTpl` 
                      &errTpl=`lgnErrTpl` 
                      &logoutResourceId=`1`
                      &loginResourceId=`13` 
                      &redirectToPrior=`0`
                      &contexts=`web,it`]]


                      and in the it context

                      [[!Login? 
                      &loginTpl=`loginTpl` 
                      &logoutTpl=`logoutTpl` 
                      &errTpl=`lgnErrTpl` 
                      &logoutResourceId=`16`
                      &loginResourceId=`23` 
                      &redirectToPrior=`0`
                      &contexts=`web,it`]]


                      I added some debug code on the first page after the login.

                      $result = '';
                      $result = $result .$modx->user->get('username') .  ' # ' .$modx->context->key;
                      $result = $result .$modx->getLoginUserName('web') .' # ' . $modx->getLoginUserName('it'); 
                      $result = $result .$modx->user->isAuthenticated('web').' # ' .$modx->user->isAuthenticated('it');
                      $result = $result .$modx->user->hasSessionContext('web').' # ' .$modx->user->hasSessionContext('it');
                      return $result;


                      When i do a login (with username 'engels' in the web context, which is succesful, i get:
                      engels # web # engels # engels # 1 # 1 # 1 # 1


                      but it goes wrong in the italian context
                      - when i do a login in the italian context
                      - when i am succesfully logged in, in the web context and then switch to the it context
                      i receive:
                      (anonymous) # it # # # # # #


                      Sombedy any ideas why i am suddenly logged in as anonymous...

                      I had this working last week.

                      The only thing that changed that i could think is some hosting setting.
                      At first i was working on a url like this
                      http://registeritaly.domain.org.server.hosting.com
                      and then they changed it to
                      http://registeritaly.domain.org

                      Could this have something to do with that????