<![CDATA[ multiple context login - My Forums]]> https://forums.modx.com/thread/?thread=83395 <![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login?page=2#dis-post-553986
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:33 AM https://forums.modx.com/thread/83395/multiple-context-login?page=2#dis-post-553986
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-537462 Quote from: BobRay at Feb 01, 2014, 06:47 PM
Another solution might have been to add the other context to the Login tag's &contexts property. I'm not sure it existed at the time of my previous post.

[[!Login? &contexts=`web,private`]]

I have the same issue, this is not working for me. I used babel for multi-language.]]>
grigkar Jan 25, 2016, 08:44 AM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-537462
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488982 BobRay Feb 02, 2014, 03:48 PM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488982 <![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488942
Contexts seemed to be the best fit for our needs: a public web context and a private context for logged in users, in a separate subfolder. (domain.com/private). I thought it would be easy to set the ACLs and so on. I guess we really need to buy your book!

Bob, I did get the Wayfinder menu to work again and it had nothing to do with switching contexts, I'm ashamed to say it was a stupid typo on my end laugh. Susan, migxMultiLang looks great! But it doesn't give you the means to set access permissions like I need to do right? But for a multilanguage site it looks like a great solution.


]]>
michelle84 Feb 02, 2014, 12:42 AM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488942
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488938 sottwell Feb 01, 2014, 11:23 PM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488938 <![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488933
There's a section in my book with the heading: "Do You Need Another Context?" wink]]>
BobRay Feb 01, 2014, 10:37 PM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488933
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488909
However when I use your snippet, I just found out I get new problems with Wayfinder not displaying a menu from the other context (in private context I want to display a menu from web context). Now I've got it working by setting loginResourceId to a resource in web context, and in that resource calling a snippet that redirects to the site start on the private context.. And that works, strange isn't it?

Contexts seem to be quite problematic!]]>
michelle84 Feb 01, 2014, 01:11 PM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488909
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488907
[[!Login? &contexts=`web,private`]]
]]>
BobRay Feb 01, 2014, 12:47 PM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488907
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488901 This is my setup:
- Login snippet is on resource in web context
- after login, user should be redirected to site start of 'private' context

This was not working, it was like the redirect could not be made cross context. There was no redirect, but I was logged in.

Bob's solution worked for me after I switched 2 lines: I had to switch contexts before I could make an url with $modx->makeUrl. Otherwise I got the error: 'Attempted to redirect to an empty URL'.

Just posted this in case anyone else runs into this problem.]]>
michelle84 Feb 01, 2014, 10:49 AM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-488901
<![CDATA[Re: multiple context login]]> https://forums.modx.com/thread/83395/multiple-context-login#dis-post-460044
return $modx->context->get('key');



You might be able to do the forward yourself in your postHook with something like this:

$docId = $scriptProperties['loginResourceId'];  // or set this to the ID of the resource you want to send them to

$doc = $modx->getObject('modResource', $docId);

if ($doc) {
   $context = $doc->get('context_key');
   $url = $modx->makeUrl($docId, "", "", "full");
   $modx->switchContext($context);
   $modx->sendRedirect($url);
}


I don't know if that would work, and there's a good chance that someone else knows a better way to solve your problem.]]>
BobRay Mar 24, 2013, 11:48 PM https://forums.modx.com/thread/83395/multiple-context-login#dis-post-460044