We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16815
    • 49 Posts
    Is it possible to log in to the manager context when logging in in the front-end, using the Login snippet?

    So if a user that has access to the manager, log in in the front-end they don’t need to log in one more time to access the manager...
    • Quote from: leaase at Aug 01, 2010, 03:54 PM

      Is it possible to log in to the manager context when logging in in the front-end, using the Login snippet?

      So if a user that has access to the manager, log in in the front-end they don’t need to log in one more time to access the manager...
      It is possible with the login processor to login to multiple contexts, but it appears as if the Login snippet only works for a single context at the moment. It would be great if you would add an issue for this at http://github.com/splittingred/Login/issues so this doesn’t get forgotten about.
        • 16815
        • 49 Posts
        The issue is added smiley
        • I needed this for something I’m working on and found a way to do this for now until this is added. This requires the user account to be in the Administrator Group and their role to include manager access. This has not been tested in depth but in some testing done seems to work right. One issue is that if you logout from the mgr it does not logout the front end. I believe there are a couple ways this could be done, but this was not critical for me at this point.

          To implement
          In Login Snippet Add:
                      /* If user just logged in is an admin also login with mgr context */
                      $user = $modx->getObject('modUser',array('username'=>$_POST['username'])); // Create user object based on username logging in
          			$userGrp = $user->getUserGroupNames(); // Get group of user logging in
          			if (in_array("Administrator", $userGrp)) { // Log into mgr context if in Administrator Group
          				$_POST['login_context'] = 'mgr'; // Set context to log into as mgr
          	            $modx->executeProcessor(array(
          	                'action' => 'login',
          	                'location' => 'security'
          	            )); // Perform login
          	        }  
          
          After line 73-76 containing:
           /* send to login processor and handle response */
                      $response = $modx->executeProcessor(array(
                          'action' => 'login',
                          'location' => 'security'
                      ));


          To support a user clicking logout on the frontend also also having them logout of the mgr context:
          Add:
                  /* If user just logged out is an admin also logout with mgr context */
                  $userGrp = $modx->user->getUserGroupNames(); // Get group of current user
          		if (in_array("Administrator", $userGrp)) { // Logout mgr context if in Administrator Group
          			$_POST['login_context'] = 'mgr'; // Set context to logout as mgr
                      $modx->executeProcessor(array(
                          'action' => 'logout',
                          'location' => 'security'
                      )); // Perform logout
                  }   
          
          After lines ~120-124 after adding previous code containing:
                  /* send to logout processor and handle response */
                  $response = $modx->executeProcessor(array(
                      'action' => 'logout',
                      'location' => 'security'
                  ));
                  
            Jason Bird
            Twitter: @jasonabird @threeeyedbird
            • 28388
            • 6 Posts
            I know this is an old thread but i’m a bit stuck with some sort of same problem.
            I have 2 subdomains on the same modx-install.
            For those subdomains i have seperate contexts and I can login on either one of them. The thing is that I want to stay logged in when I login on one context and switch to the other context.

            This "hack" above might work, but I’m wondering how the login snippet should be setup since it has support for this now (if I understand it correct).
            Can somsone tell me what I have to set in my login-chunk or in the properties of the login-snippet to get this working?
            Any help is appreciated.
              • 28215
              • 4,149 Posts
              &contexts=`web,otherctx,anotherctx,etc`
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com