We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Hi guys,

    I have a Snippet which checks to see if the user attempting to view a page in a website is currently logged into the MODx Manager as an Administrator. If they are, then they are allowed to view the page, it not they are shown the unauthorised page. This works fine... BUT, the site in question also allows website front end members to login, and if the website Administrator is logged in as a website user as well as being logged into the MODx Manager then this snippet fails, and reports that the user is not logged in as an admin user - it seems the website user is seen before the modx manager data. Any ideas on how to resolve this?

    <?php
    /* AdminOnly snippet */
    if (! $modx->user->isMember('Administrator')) {
       $modx->sendUnauthorizedPage();
    }
    
      • 4172
      • 5,888 Posts
      does he login with another account(username/password) at fronend or with the same account as at backend?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 8168
        • 1,118 Posts
        Quote from: Bruno17 at Jan 08, 2015, 06:48 AM
        does he login with another account(username/password) at fronend or with the same account as at backend?

        Yep, this issue occurs when signed in to the frontend with a different account to the Manager. I guess easiest to make him login with the same creds that he uses to login to the Manager - I guess that will work as he is an Administrator in the Manager therefore.
          • 4172
          • 5,888 Posts
          yes, if he isn't in the Administrator-group with his frontend-account, this

          $modx->user->isMember('Administrator'))


          will return false, because the current modx-user logged into the frontend-context isn't in that group.



            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 40706
            • 128 Posts
            I had an Project where i used multiple contexts with subdomains checking if users are auth`ed on others.
            Think this should give u also the userId of the manager context. Just get the modUser Object and use isMember on em

            $userid = $modx->getLoginUserID('mgr');