Help with Login Extra (New to MODX)

Hi all, new to MODX and loving it so far. I am having trouble understanding the Login Extra to create a section of my site behind a login. I am using 3.0 beta 2, and doing my best to follow this tutorial:

https://docs.modx.com/3.x/en/extras/login/login.tutorials/basic-setup

I have gotten past “Create the Necessary User Groups and Resource Groups” with no problem by finding appropriate changes made in the newer UI versus what is shown in the tutorial, but I am getting stuck in the “Add Snippets to Pages” section:

[[!Login?
&loginTpl=`lgnLoginTpl`
&logoutTpl=`lgnLogoutTpl`
&errTpl=`lgnErrTpl`
&loginResourceId=`4`
&logoutResourceId=`5`
]]

(1) &loginResourceId=4 : Am I supposed to leave that as ‘4’ or change it to the id of a page, snippet, or chunk?

(2) &logoutResourceId=5 - Same question.

(3) How do I set which page successful logins go to?

(4) Am I supposed to simply have the Login Snippet above on a blank page with no template, or is it supposed to be included somewhere?

I am sure these seem like idiotic questions, but I can sure use some help. Soon I will surely be running into questions with Wayfinder, but I am loving MODX so far! :slight_smile:

(1) Id of a page
(2) Id of a page
(3) That’s what the property &loginResourceId is for (see your question (1))
(4) Put it in the template (or content) of a normal page

Maybe also use the documentation of this snippet as a source for potential further questions.

Thanks for answering most of my questions. I am still running into some issues but will continue messing with it until I get it right.

That said, if you don’t mind a little reference to the last line in the reply. I posted the link to the docs I was referring to, and it might be implied that since I was referencing section 9.1 of Login Extra docs, I probably already went through section 1, and remained confused. As such a natural inclination is to google for hours looking for help, search out youtube videos for help, search these forums, for help, and finally ask. This is what I did.

I will have further questions as time goes on, as I am learning something that is entirely new to me. We have all been there, and surely we can all remember the times someone has assumed we should have not only read, but understood the docs before we asked a question. We often forget how overwhelming some things can be at first until it all starts to click, and hopefully we remember that this is the specific reason forums like these exist.

In choosing MODX, It was not lost on me that many people have been asking the question “Is MODX DEAD?” I have read through all of those posts, but remain very impressed by it. As a guy that comes from more than 20 years in the CFML community, I have been living that question for a long time, and I can say this: Platforms die when new users to the platform are not entirely embraced.

I hope this is read in the spirit intended. I promise I will have what seem to be stupid or lazy questions as I continue. None of them will be stupid or lazy to me. I will have tried to learn on my own. I hope to find a welcoming community here that is eager to help me become a cheerleader for MODX that can later start helping other new users.

This line wasn’t meant to be condescending or to offend you.

I just didn’t know if you had seen this page and thought it could be helpful, as it contains a detailed description of all the properties.

I’m happy to help if you have other questions.

Thank you so much. I wasn’t offended. I just wanted to make it clear that while I am new to MODX, I am not one of those people that ask for help without really digging what I perceive to be deep first. That was the spirit intended, and really hope to find a great community here.

I love how flexible it is, and I fully embrace that with that kind of flexibility comes a learning curve, and also a realization that there are usually countless ways to reach desired outcomes.

I am still having trouble with it, but at least I got to the point in which when I seemingly get a successful login, I am getting a 404. Oddly, to get the login, I have to repeat username and password twice. I am chasing that down. I am very driven to get myself proficient :slight_smile:

This probably means that the user hasn’t the permission to access the resource you set in the &loginResourceId property.

Maybe first use a unprotected resource as &loginResourceId to make sure that the login/logout process works and then figure out the access rights later.

Or test the Login snippet without the &loginResourceId property at all.

[[!Login]]
<hr>
[[!+modx.user.id:isloggedin:is=`1`:then=`Logged in`:else=`NOT logged in`]] 
1 Like

Or it’s not published.

Welcome to MODX. :slight_smile:

I think you’ll find that people here are very welcoming to newbies and very tolerant of questions at any level. That’s one of the main things that attracted me to MODX in the first place.

2 Likes

Indeed. @mkovnick, you’ll find lots of help, patience and a wide variety of solutions in the MODX community. If we’re not learning something new from others every day, what’s the fun?

1 Like

Thanks all. OK, so I am still having the same issue and hitting a brick wall. I am sure I am missing something obvious and will kick myself, but maybe if I take you through what I have done (as I have understood from the docs and tutorial)… Keeping in mind the docs and tutorials are referencing older versions, and I am using V3 Beta II. So here goes:

  1. In Content|Resource Groups, I created a group called “backend_access”. Context: Web, Admin Group Access: Checked, Parallel User Group: Checked, Anonymous Access: Unchecked.

  2. I created a new user named “mck”. Set to active, and in the Access Permissions tab, I added the user to “backend_access” with the role of “Member”.

  3. Checking in Settings|ACL, and clicking the backend_access group, I see my user there as mck member - 9999

So at this point, it seems that based on the docs I am golden.

Now, I have installed the Login Extra, and I am trying to get this to work with the default chunks installed with the package before I decide to style them, so I created pages as follows:

1) Reservations (7)
Essentially, I have this as the main page, because the url will me mysite/reservations.
Template: Empty Template
Published: Yes
Resource Groups|backend_access: Checked.
Content: I have the following:

[[!Login?
&loginTpl=`lgnLoginTpl`
&logoutTpl=`lgnLogoutTpl`
&errTpl=`lgnErrTpl`
&loginResourceId=`13`
&logoutResourceId=`12`
]]

2) Home (13)
This is where I would have users redirected after a successful login, and I want everything in this area protected.
Template: BE_Template
This is a template I created for my backend admin panel
Published: Yes
Resource Groups|backend_access: Checked.
Content: None, I am hoping just to see my template pull up after a login.

2) Home (13)
This is where I would have users redirected after a successful login, and I want everything in this area protected.
Template: BE_Template
This is a template I created for my backend admin panel
Published: Yes
Resource Groups|backend_access: Checked.
Content: None, I am hoping just to see my template pull up after login.

3) login (9)
Template: BE_Template
According to the docs, I needed to create the page
Published: Yes
Resource Groups|backend_access: Unchecked.
Content:
[[$lgnLoginTpl]]

4) forgotPass (10)
Template: BE_Template
According to the docs, I needed to create the page
Published: Yes
Resource Groups|backend_access: Unchecked.
Content:
[[$lgnResetPassTpl]]

5) resetPasswordHandler (11)
Template: BE_Template
According to the docs, I needed to create the page
Published: Yes
Resource Groups|backend_access: Unchecked.
Hidden from menus
Content:
[[$lgnResetPassChangePassTpl]]

6) loggedOut (12)
Template: BE_Template
According to the docs, I needed to create the page
Published: Yes
Resource Groups|backend_access: Unchecked.
Content:
<p>You have been logged out</p>

Surely someone is looking at this and seeing several bonehead things I am messing up on… At least I hope so! That is what I have been able to gather from the docs, while also using the new UI.

Here is the behavior I am experiencing:

First know that I am clearing the cache in the UI, flushing permissions, and clearing browser cache each time I make an attempt.

  1. When I got to mysite/reservations, I am indeed presented with the base login page I am expecting.

  2. When I log on with the mck user I created I assigned the permissions to, I am presented with the login page again. But when I enter the user and password a second time, it logs me in.

  3. When I am logged in, I do not see any of the pages I expect. I see a simple blank page with a Logout link.

OKJ, I am ducking for the idiot bomb now :slight_smile:

Your page with the [[!Login]] snippet (Reservations (7)) can’t be in a resource-group. The page has to be publicly accessible so that users can access it to log in.

Also, I don’t think you need the pages 9 to 12. If you want a different markup for the login form, create a new chunk and reference it as the value of the property loginTpl in the call to [[!Login]]. You don’t need a page for that.

Also, I don’t think you want to use the empty template unless your page content contains html, head, and body tags.

If you want to allow users to reset their passwords then you can use the pages 10 and 11 for that, but the content has to be different.

Probably [[!ForgotPassword? &resetResourceId=`11`]] for your page 10 and [[!ResetPassword? &loginResourceId=`7`]] for your page 11.

But these pages aren’t required for Login to work.


The same with the logout page (12). It’s not wrong but also not required.

Thanks all, ok, so I am feeling a little less dumb, and seem to be on the same track, but still not getting the results. I simplified it based on the above suggestions, figuring the more we simplify this the better. If I can just get a successful login, I can worry about forgot password, logout, and all of the other bells and whistles later.

New config

  1. No change to user and group
  2. Deleted all pages except Reservations (7) and Home (13)
  3. Reservations (7) is now unrestricted.
  4. Reservations (7) Still uses an empty template, but I put the HTML in there as follows:
<!DOCTYPE html>
<html lang="en">
<head>
  	<meta charset="utf-8">
  	<title>Login</title>
  	<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    [[!Login?
    &loginTpl=`lgnLoginTpl`
    &logoutTpl=`lgnLogoutTpl`
    &errTpl=`lgnErrTpl`
    &loginResourceId=`13`
    ]]
</body>
</html>
  1. Home (13) remains unchanged. Using my backend template, and restricted to backend_access group.

The resulting behavior is unchanged:

  1. when I go to /reservations, I get the login form.
  2. When I enter username and password the first time, it brings me back to the login form.
  3. When I enter username and password the second time, I get the following resulting page (which is not my expected Home Page (Resource 13):
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <div class="loginMessage"></div> <br />
    <div class="loginLogin">
        <div class="loginRegister"> <a
               <a href="/reservations?service=logout" title="Logout"></a>
         </div>
    </div>
</body>
</html>

I tried out your exact process on a local MODx 3 beta 2 installation (just to make sure that this is not an issue with MODx 3) and everything worked as it should.

It’s very weird that you have to enter username/password twice.


What is in your template “BE_Template”? Just some simple markup or do you have other snippet calls?

<!doctype html>
<html lang="en">
<head>
    <title>[[*pagetitle]] - [[++site_name]]</title>
    <base href="[[!++site_url]]">
    <meta charset="[[++modx_charset]]">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<div class="container">
    <section>
        <h1>[[*longtitle:default=`[[*pagetitle]]`]]</h1>
        [[*content]]
    </section>
</body>
</html>

The output in your ‘Home Page’ seems to be the content of the chunk “lgnLogoutTpl”.

<div class="loginMessage">[[+errors]]</div>
<br />
<div class="loginLogin">
    <div class="loginRegister">
        <a href="[[+logoutUrl]]" title="[[+actionMsg]]">[[+actionMsg]]</a>
    </div>
</div>

When you check the address bar of the browser, on what page are you when you see this output?


Maybe also check the system settings error_page, unauthorized_page and site_start and make sure they point to published and unprotected resources.

Wow, I am getting frustrated to the point that I may try a clean install and see what happens. That said, here are the answers to the above post:

  1. My BE_Template currently is simple HTML, with all relevant sections in chunks. Just trying to just get a skeleton working for now before I start dealing with snippets. Still, to simplify even more, I replaced the BE_Template with the exact skeleton you posted above, and still have the same result.

  2. Yes, the output when I get logged in is the exact content of the lgnLogoutTpl chunk (RID 19). However, the output of my Home (actually not the home, but the home of the backend (RID 13) is not being shown.

  3. error_page is set to RID 15, published, unprotected.

  4. unauthorized_page is set to RID 17, published, unprotected.

  5. site_start is set to RID1, which is my public-facing home page.

On the system settings, the error pages uses a template called ErrorTemplate. This template has a simple HTML skeleton, and I am putting the error description in pagetitle and content of the individual pages.

All of that said, I have more info on the behavior that may lead to a clue.

Remember, the unprotected page people land on has the following in the template (wrapped in an HTML skeleton):

    [[!Login?
    &loginTpl=`lgnLoginTpl`
    &logoutTpl=`lgnLogoutTpl`
    &errTpl=`lgnErrTpl`
    &loginResourceId=`13`
    ]]

When I land on this page, I get the login for from lgnLoginTpl, using the default installed with the package. It does show the correct pagetitle for that page (“Reservations”), which is RID 7. I view the source, and it is exactly what I expect. I enter username and password once, and I am shown the login for again with no errors (still showing the same pagetitle). If I view source this time, I am asked to confirm form resubmission, if I do so, I can see that the resubmission is logging me in this second time.

If I enter my username and password a second time, I am still only seeing the Logout link, but since the template now includes pagetitle, I am still seeing the page title “Reservations”, which belongs to my unprotected landing page. For whatever reason, the Login call on that page is now pulling in lgnLogoutTpl, and is not sending me to RID13, as I would expect.

A shot in the dark, but it may help to have some more info about my config. I am using friendly urls, and the server is set up as follows:

Ubuntu 18.04
Apache2 2.4.29
PHP 7.4.26 - As an aside, I attempted to install MODX with PHP 8, and it failed.
MariaDB 15.1 (Distrib 10.1.48-MariaD)

That’s maybe not a bad idea to see if you can reproduce the issue.

As far as I can tell your setup is correct now. I myself can’t reproduce these problems and I couldn’t find similar problems with Login on github.

Maybe even just try it on a clean install without the resource group and different users. Just try if you can create a login page that redirects you to another page (without showing the login-form twice) when you log in as the admin.

Yep, this thread and all that have contributed have been a huge help. I’m going to try a clean install of 2.8, and save 3.0 for later. I will let you know what happens.

BAM! Fresh install of 2.8 and have it working (for the most part)

  1. I tried as suggested with no resource group, and it worked.
  2. I added a new user, logged in with the new user, and it worked.
  3. I added a resource group, added that group to my target page, logged in, and it worked.

The only issue I have now is if the new user is not given permissions to that group, I get a 404, but I am assuming now that it is simply because I haven’t setup error_page or unauthorized_page Yet.

Very happy!

1 Like

If you want to display the unauthorized page, you have to give the anonymous user group the “load” permission.

1 Like

OK, I know I am close here. The anonymous user already had load permission. I tried Load/List View, and still getting no page.

Does this look right for the anonymous user??

here is the page when I try to login as a user without access to the page:

And View source gives me: