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

    In *cough* Drupal *cough*, I could have a single navigation link for Login and Logout. I achieved that by creating 2 navigation links, i.e. "Login" and "Logout" links. And set the "Login" link for the public users and "Logout" link for registered users. So the public users will be given a login form when they click the "Login" link. When they successfully logged in, they will be redirected to the main site’s index.php, then the link’s title will be changed to "Logout". They will be logged out and redirected to the main site’s index.php when they click it.

    How could I do that in MODx?

    I am sorry to ask this as I could not find the solution after a few hours trying and reading the documents. Maybe I missed them. So if you could point the documentations related to this, I would really appreciate that.

    Thanks a lot in advance for your help.

    Anto
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      WebLogin does this automatically. If you examine the default template, and the code, you’ll see that the template is divided into three parts. The second part is displayed if the user is logged in (the logout link); the third part is managed by the javascript and is the "forgot password" form. The first part is the login form, and is only displayed if the user is not logged in.

      There are a couple of other snippets that check the login status and display different chunks if the user is not logged in or is logged in. So there are a number of ways you could handle this.
        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
        • 1808
        • 13 Posts
        Thanks a lot Susan.

        I have actually tried WebLogin, but maybe I was not trying hard enough smiley I didn’t notice that the key to achieve this is the Template Variable, i.e. [*loginName*]. I can finally have the title of the menu button changed depending on whether I logged in or not as I wanted. But I found 2 problems sad

        1. I can set the TV for the document’s Title and Menu title, but not the Document’s alias. Every time I set it to [*loginAlias*], the [* and *] characters straight away stripped off after I clicked the Save button. The loginAlias that I used is like below.
        @EVAL if ($modx->getLoginUserID()) return 'logout'; else return 'login';

        That is actually the copy of [*loginName*]. With that I expected to get login.html and logout.html URL aliases, which is changing the same as the change of the Title and Menu title. What is the point to have those 2 changed but not the URL alias?

        2. It looks like this problem is related to the previous one. After I logged in, I can not logout anymore. That because the logout link produces the web request /login.html?webloginmode=lo which of course ends up at 404, as I am using the Friendly URL. At the moment, I just workaround that by bypassing it so my Lighttpd does not execute the lua script for MODx. It looks ugly though sad

        Does anybody have any comments or suggestions about this?
          • 22303 MODX Staff
          • 10,725 Posts
          You don’t want the alias to be dynamic, and that’s not possible anyway. Pick a generic alias like security or access.
            • 1808
            • 13 Posts
            Shouldn’t that be the job Friendly URL? Which is to map the query codes into the static URL? I am sorry to ask, but could you please explain the disadvantage of having dynamic alias?

            One point I would like to mention, I hope this would not upset you. Drupal can do that, why not MODx?
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: anto at May 03, 2008, 06:47 PM

              Shouldn’t that be the job Friendly URL? Which is to map the query codes into the static URL? I am sorry to ask, but could you please explain the disadvantage of having dynamic alias?

              One point I would like to mention, I hope this would not upset you. Drupal can do that, why not MODx?
              Universal Resource Locator’s for distinct documents should not change. This is a no-brainer if you want consistent search engine rankings, and generally, makes it easier for people to bookmark links in your site. Why in the world would you want a page’s URL to change? It just doesn’t make any sense to me; I definitely do not see any advantage, but perhaps I’m missing what you are trying to achieve.

              And mentioning what Drupal does certainly isn’t going to upset anyone; I’m more interested in why you would want the same page to change URL’s; seems like that would make it hard to find what you are looking for...
                • 1808
                • 13 Posts
                Jason,

                I 100% agree with you that URL as a whole page should not be dynamically changed, as that will not make it Search Engine Friendly and screws up the user’s bookmark.

                As I mentioned above, what I would like to achieve is to have navigation link which is dynamically changed. The problem with most of all CMS’ is, the navigation link ties directly to a page or document. Like in MODx, there is no way to separate the configuration of the menu from its related document. So the URL alias goes together with them which I think makes this discussion diverted.

                I think the different between MODx and Drupal is the way to assign access permission of a page or document. In MODx, if we assigned the access permission of a document to public users then that document will also apply to the registered users. To my understanding up to now, we can not separate that permission assignment. I hope I am wrong, but I still could not find a way to do it.

                Ok. Back to my question. I still strongly believe it can easily be done in MODx. After some readings, I think I can achieve that by doing these:

                1. Create a "Registered Users" document group, and assign the user group of "Registered Users" to that document group.
                2. Create a "Login" and "Logout" documents with their independent URL aliases and menu settings with "Show in menu" (donthit bit) both ticked.
                3. Allow only "Registered Users" accessing the "Logout" document.
                4. Create snippets to change to intercept the "Login" document parsing and change its donthit bit to 0, when the login is successful.
                5. Create snippets to change to intercept the "Logout" document parsing and change the donthit bit of "Login" document to 1, when the logout is successful.

                What do you think about that? Or is there any easiest way to do it?

                I still can not make the point 4 and 5 working up to now. So I really need help from the experience MODx PHP coders, like you laugh

                Cheers,

                Anto