We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Hi, I’m a new MODX user and I’m trying to do the following:

    I’ve got a page that should only be visible to logged in Manager Users on the ’frontend’ of the website. I’ve tried all sorts of things, but the problem seems to be that I can only set accessibility of pages to Web User groups. So if I log in as a Manager User I can still not see a certain page that is only visible to a group of Web Users on the frontend of the page (I’m using the ManagerLogin snippet and the QuickEdit module to edit pages on frontend).

    Does anyone know if the thing I want is possible? I also tried the Web2Manager plugin but from what I can see this only creates a web user that has the same username and password as a manager user. But if I login as a manager I still don’t see the specific page that is assigned to the web user with the same login credentials.

    So in short I would like to do the following:
    - login on frontend as manager user with ManagerLogin snippet
    - be able to edit pages with quickedit on frontend
    - be able to see manager-only pages on frontend

    Thanks in advance for any help!!
    BTW, I’m using ModX 0.9.6.3

    Michelle
      • 21561
      • 16 Posts
      Hi Michelle, Welcome to Modx.

      The best damn cms on the planet and as far as i know the galaxy

      try using $modx->getLoginUserType(). it will return either web or manager.  if you want to see how the function works check out line 2015 in  manager/includes/document.parser.class.inc.php
        • 4041
        • 788 Posts
        For this I recommend creating a new template specifically for the pages you want to protect with this snippet.
        Take the code below, create a new snippet (name it whatever you want, I used Manager_only but it doesn’t matter).
        Modify the $redirect_url to match whatever page you want to redirect non logged users to.
        Add the snippet call to the top of the template (use uncached: [!Manager_only!] )

        <?php
        /*   Manager_only
              checks to see if a manager session is found, if not
              redirect them to $redirect_url
        */
        
        $redirect_url ="http://yoursite.com";
        if(!isset($_SESSION['mgrInternalKey'])){
           header("Location: $redirect_url");
        }
        ?>
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 19328
          • 433 Posts
          Wow, thanks so much! Modx is indeed a fantastic CMS, and with a friendly community!
          Breezer, your suggestion works perfectly! Is there also a way to make the menu-item only appear in the menu when logged in?
            • 4791
            • 10 Posts
            Quote from: Breezer at Apr 25, 2009, 04:15 PM

            For this I recommend creating a new template specifically for the pages you want to protect with this snippet.
            Take the code below, create a new snippet (name it whatever you want, I used Manager_only but it doesn’t matter).
            Modify the $redirect_url to match whatever page you want to redirect non logged users to.
            Add the snippet call to the top of the template (use uncached: [!Manager_only!] )

            <?php
            /*   Manager_only
                  checks to see if a manager session is found, if not
                  redirect them to $redirect_url
            */
            
            $redirect_url ="http://yoursite.com";
            if(!isset($_SESSION['mgrInternalKey'])){
               header("Location: $redirect_url");
            }
            ?>


            Is it possible to have it so that pages will only be viewable to logged in users (not just managers)? I suspect you would just change mgrInternalKey to something like usrInternalKey but I don’t know what the variable is called. Any ideas?
              • Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 4791
                • 10 Posts
                Thanks. Sorted it right after posting that by changing it to "webInternalkey". That site looks like a good resource though - much appreciated. smiley