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

    I try to achive following result.

    I have a menu with different entrys. One entry is marked as private the other on is marked as public. When I am not logged in, only the public one is displayed. When I am logged in both menu entries are displayed.

    The goal I try to achive is, that all menu entries are displayed. When I access the privat menu the login screen will be displayed.

    How can I achive this?

    Thanks for your help
    • Are your menus hard coded, or is there an entirely separate set of folders in your menu tree for the logged in users?
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • You’ll need a snippet to put on the page to check the user’s login status, if he’s not logged in to a group that you have determined, it redirects to a login page, which in turn will redirect back to the original page.
        It would even be better to call the original snippet in a TV with @INHERIT so that all children of your protected page will also be protected, thus preventing direct URL into the subfolder pages.
          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
          • 17875
          • 3 Posts
          Thanks for your help.

          Unfortunately I am not a programmer, so it is difficult to write a snippet. As far as I understand I have to change the DropMenu Snippet, because this is responsible for creating the menu.

          This is what I try to create (independent from login state)

          Menu
          +HOME (free)
          +PICTURE (free)
          + Gallery 1 (free)
          + Gallery 2 (restricted)

          That is what I get (not logged in)
          +HOME (free)
          +PICTURE (free)
          + Gallery 1 (free)

          What I need is an idea what to change their.

          Quote from: rthrash at Feb 20, 2006, 12:22 AM

          Are your menus hard coded, or is there an entirely separate set of folders in your menu tree for the logged in users?

          The menu is build of separate folders.
          • No, you won’t need to change the DropMenu snippet. It will be used as normally to display all of the links. But your Gallery2 page will have a snippet in it that checks for the user’s logged status (checking the SESSION for web groups) and if he doesn’t have the proper web group listed in his SESSION, he gets sent off to the login page. The login snippet can be called with the option of which page to go to on login, that would be Gallery2. Now the user has the proper web group listed in his SESSION, and can view the page.
              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
            • This seems to do the job. Create a new snippet named CheckUser with this content:

              // CheckUser snippet
              // checks to see if user is a member
              // of a given web user group
              // redirects to given login page if not.
              //
              // options:
              // &group - the group the user must be a member of
              // &page  - the page ID of the login page
              
              if(!isset($group) || !isset($page)) return; // can't do much without these!
              $group = array($group);  // isMemberOfWebGroup needs an array.
              if($modx->isMemberOfWebGroup($group)) return; // if we are, quietly exit.
              $url = $modx->makeURL($page); // we didn't exit, so must not be a member of group
              $modx->sendRedirect($url); // so make the url to the login page and go there. 
              return;
              


              On the login page, call the WebLogin snippet like this:

              [!WebLogin?loginhomeid=`xx`!]


              where the xx is the ID of your Gallery2 document.

              At the beginning of your Gallery2 document, call the CheckUser snippet like this:

              [!CheckUser?group=`galleryuser`&page=`xx`!]


              where the xx this time is the document ID of your login page, and galleryuser is the group you make for your gallery users.
                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
                • 10190
                • 187 Posts
                I think it would be very nice to have such a feature - "restricted" or "login required" or similar - as a standard property of folders and documents in further versions.

                It makes the use of accounts more attractive to users, thus decreasing the amount of anonymous users. Furthermore one could show the links of restricted areas, ie. a restricted folder with some restricted documents, to raise users curiosity (by reading my own writing I get the impression I should join the marketing team) laugh

                Anyway, restricted areas are part of many sites, it would be great to have such a feature with modx!

                Am I supposed to write a feature request?

                Frisco
                • We are trying to minimize core features, making the "extras" optional plugins, snippet or TVs. This way the core is kept clean, small and fast, and users can add any extra features they want.
                    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
                    • 17875
                    • 3 Posts
                    Hi

                    Thanks for the detailed help. I will try it a soon as I have time.

                    .madcat999
                    • When testing my "theory", I found that if I put " (Login Required)" in the page description of the private pages, leaving this empty in all other pages, then hacked the DropMenu snippet to replace the $post variables where it generates the links to $child[’description’] it then nicely appended that to the link text. You could even put in "<span class="private"> (Login Required)</span>" and then style the text in size and color.

                      Maybe someday the DropMenu snippet will evolve (or be intelligently designed grin ) to use user-defined templates with placeholders for the links.
                        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