We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28825
    • 61 Posts
    Hey everyone, quick question:

    What I want my site to do is essentially check to see if a user is logged in, to show them one page, and if not logged in, to show them another version of that page (with maybe some buttons "greyed out" as if they were inaccessible). However, I also don’t want accessing the logged in page to be child’s play (by the user somehow typing the direct URL of logged in page). Is there anyway to do this easily with ModX?

    For more information: User Log in will be handled through a floating window that loads on top of the page when the user clicks "log in". After logging in, the user is taken to a page where they have access to ALL the same links as public users, but they will now see the "private" features enabled on all of those pages (whereas the public users see buttons on those pages grayed out or they get a message saying they need to log in).

    P.S. By any chance, does this have something to do with session cookies and having the web page check, in the head of the document, whether a session is active or not?

    Thanks for all your help wink
      "Don't waste your time or time will waste you"
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There are snippets to check a user’s login status and do various things. This one will display a given chunk.

      http://modxcms.com/extMemberCheck-1320.html


        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
        • 28825
        • 61 Posts
        Awesome, thanks a bunch Susan! laugh

        Just a quick question: Let’s say that I only want to display a specified chunk if a user is logged in, but if they are NOT logged in, then what page will be displayed by default?

        The snippet above seems to display chunks relative to the users group. But I actually only have one group : "registered users". The other "group" is technically all visitors from the world wide web. So lets say I put the snippet at the top of my page and it finds that the user in question is not logged in and not part of any group, will it default to displaying the page as is?

        I will try to search the repository for other scripts in the meantime.
          "Don't waste your time or time will waste you"
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It will display the normal page to all users. The snippet will load the specified chunk into the page for logged-in users. Doesn’t matter how many groups you use, if the user belongs to the group you specify the chunk will be added to 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