Modx login and multiple contexts

Dear colleagues,
Our company is developing web sites, based on modx for years.
This is one of the best CMS I ever used
And your community is one of the most valuable sources of information and additions for modx.
My question is related to multilingual modx revolution (2.3) site, based on context switching and Login (Login module).
I was fighting for hours to make the login work for all the frontend contexts.

The multilingual implementation is not with subdomains, but with «folders»
domain.tld/bg/ domain.tld/en/…

Adding &contexts parameter to Login call didn't help

I found some threads in modx forums, which didn't help either.

I managed to make it work, by adding following code to index.php
switch ($_REQUEST['cultureKey']) {
        case 'en':
            $modx->initialize('en');
            break;
        case 'it':
            $modx->initialize('it');
            break;
        default:
            $modx->initialize('web');
            break;
    }
But the login is per context (You have to login to each context separately).
Do you have an idea how can I achieve single login to all frontend contexts.
I would expect such a solution will be useful for other people as well.

Sorry that I'm posting in English, my Russian writing skills are a bit rusty, but you can answer in Russian.

Kind Regards,
Dimitar Dimitrov
03 ноября 2014, 14:59
modx.pro
3 089
+1

Комментарии: 7

Василий Наумкин
03 ноября 2014, 18:06
0
First of all read this article. There is no need to edit index.php or create folders.

Than you need to specify contexts in Login call:
[[!Login?
	&contexts=`web,en,it`
]]
    Dimitar Dimitrov
    03 ноября 2014, 18:30
    0
    I did it exactly as shown in your article.
    Actually I used the article to create the multilingual switching.
    And the login I called as you suggest.
    But the login didn't work (worked only for web context).
    Then I added
    $modx->initialize('$context');
    before
    $modx->switchContext($context);
    and it didn't work either.

    After I added this to index.php it started to work, but independent per context.
    If you are logged in in web (bulgarian), you are not logged in in en.
    If you login in all context it keeps you logged in
    I think it is somehow related to the user object and probably to the cookie, but for the moment cannot find the reason.
      Василий Наумкин
      03 ноября 2014, 19:14
      0
      Did you try to login from anonymous mode of browser (with no cookies and session)?
        Dimitar Dimitrov
        03 ноября 2014, 19:41
        0
        Yes.
        And from different browser as well.
        The strange thing is that people say it should work.
        Most of the discussions are actually for subdomain based multilingual implementation.
        I have to evaluate the Login code and see how the contexts parameter is working. It looks to me that it authenticates the user for current context only.

        But I can try to sell current behavior to the customer as a feature — separate logins per language :-)
          Василий Наумкин
          03 ноября 2014, 20:12
          0
          Here is working solution.

          s495.h1.simpledream.ru/manager/
          s495
          AlO24TcXPaYP

          Contexts:
          s495.h1.simpledream.ru/
          s495.h1.simpledream.ru/en/
          s495.h1.simpledream.ru/it/

          User for test:
          test
          12345678

          Maybe you forgot to add ACL for users — see it on example site.
            Dimitar Dimitrov
            04 ноября 2014, 12:04
            0
            Yes, it is working.
            I created new site and it is working as well.
            Now I have to find out what is the difference with the not working one.
            Thank you.
              Dimitar Dimitrov
              10 ноября 2014, 21:13
              0
              Found out the reason for not working login.
              If your default context is with base_url "/" everything is working.
              If the context is with «folder» for example "/bg/" the behavior is as I initially described.
              So, the conclusion is — for multilingual sites and login, leave the default context with / base_url
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      7