<![CDATA[ Login snippet and multiple contexts - MODX Community Forums]]> https://forums.modx.com/thread/?thread=18740 <![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-553985
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`
]]
]]>
stefan79w Sep 19, 2017, 09:31 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-553985
<![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102771
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.





]]>
wshawn Jun 16, 2011, 05:26 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102771
<![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102770 session_cookie_domain setting.]]> swespi May 12, 2011, 02:35 PM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102770 <![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102769 http://modxcms.com/forums/index.php/topic,57908.msg364401.html#msg364401]]> theuros May 12, 2011, 08:40 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102769 <![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102768
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.]]>
swhole247 Mar 31, 2011, 05:02 PM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102768
<![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102767
Thanks again.

Hope you manage to sort your problem out.]]>
webdesig Feb 27, 2011, 11:32 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102767
<![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102766
<p class="error"><strong>[[+msg]]</strong></p>

That’s it, just the one line]]>
scott_gb Feb 25, 2011, 09:34 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102766
<![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102765
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]]>
webdesig Feb 24, 2011, 03:31 PM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102765
<![CDATA[Re: Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102764 scott_gb Feb 23, 2011, 11:44 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102764 <![CDATA[Login snippet and multiple contexts]]> https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102763
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
]]>
scott_gb Feb 23, 2011, 10:53 AM https://forums.modx.com/thread/18740/login-snippet-and-multiple-contexts#dis-post-102763