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

    Here is my Scenario:

    I am building a site where the entire application is behind a login. The only page that is accessible to the public is the actual login form. In the event that someone should try to visit a page while not logged in, I would like to redirect them to the login screen and be able to return them to the page that they were trying to view once they login successfully.

    From my research, it appears that writing a plugin to make use of the OnPageUnauthorized system event is the best approach for this.

    So far I have setup WebLoginPE to log users in and I have set the login form as the ’Unauthorized Page’ for my site.

    A few questions:

    1 - Is this the best way to go?
    2 - Considering I am using WebLoginPE, what is the best way to store the ID of the page so that I can use it with WebLoginPE to redirect successfully?
    3 - I have considered that WebLoginPE might be making the scenario more complicated as it requires a document ID to redirect, rather than just the alias. Would you agree?

    Thoughts are appreciated.

    Thanks.
      • 4310
      • 2,310 Posts
      I did something similar for a site a while ago.
      All I did was have the the home page (id = 1) with the login form.
      I also set it as the site start, the page not found & unauthorised page.
      All other pages were locked to a Registered Users group.
        • 3749
        • 24,544 Posts
        I think you could also (for Evolution) put a call to a snippet like this at the top of your template:


        $loginPageId=1
        
        if (! $modx->userLoggedIn()) {
             $modx->sendRedirect($modx->makeURL($loginPageId));
        }
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting