Member-Only Pages

This isn’t my place, but that sounds like a misconfigured login…make sure the login code you are using there works in a basic template

Pls check the error log for any errors

It could also be an error in the code from the article. I’ll try to find time to look into it.

Hey Bob,

I got that working great. Thanks. It was an error on my part. I was missing a second ] in the snippet call. A rookie error :frowning:

Can I ask your expert opinion on this. I’ve created 3 pages;

  1. Login
  2. Editor
  3. Directory

I’ve 2 user groups created also;

  1. Editor
  2. Media

User group Editor will see the pages Edit and Directory. User group Media will only see Directory. My question is this, when a user Media logs into directory.html and then logs out, how do I get the URL to stay at …/directory.html?service=logout and not redirect to the login.html URL.

I tried using this: <.a href="[[~[[*id]]? &service=logout]]" title=“Logout”>Logout </a.>

It keeps the URL but doesn’t actually log me out.

That’s a good question. Do you have a Login snippet tag in the template of the Directory page (or in its page content)?

No. I have the login snippet in the login page and the private page snippet in the directory page. I do have the logout code that I mentioned above.

If I could get a logout code thats working on the Directory and Editor pages that logouts out but keeps, shows the login template but keeps the directory or editor url, that would be great.

Since users who are not logged in won’t see the page, you could put a tag for Login on the page or template, and style it with CSS to just show a Logout button. That should keep them on the same page. I could be wrong.

I have created a snippet that reads the user group and will direct the user to the appropriate page. When they both logout, it send them both to the login page. I’m happy with that. Thanks a million Bob for all your help to date.

1 Like

Any chance you could share some working code with future members? Its been a great thread and wonderful that you’ve got a working solution.

I look forward to the near future, when members sites can be created by new Modx users quickly and as close to effortlessly as possible. I think this new forum is brilliant~!

I will do. I’ll just wait until I have everything 100% complete. Almost there now.

1 Like

Hi guys,

It’s been a while. I’ve had this project working for a while now but forgot to add my final notes. So here it goes. The main thing to use is Bob’s The Easy Way Step by Step Guide and the Making Member Only Pages. It was so helpful. I created 3 pages;

  • Login.html
  • Editor.html
  • Directory.html

I then created 2 user groups;

  • Editors - The editors will see all the pages
  • Media - the media will only see the Directory page.

I downloaded the Login Extra and added this snippet below to my login.html page

[[!Login? &contexts=web &postHooks=PrivatePage_Login_Redirect &tplType=modChunk &loginTpl=lgnLoginTpl_NewDesign]]

I added extra parameters to personalise my project like the Login Template and Redirect.

I created the Put It All Together snippet (I called the snippet - PrivatePage_Login) from Bob’s Easy Way tutorial and added them to specific HTML pages.

[[!PrivatePage_Login? &userGroups=Administrator,Editor]] - Editor.html page
[[!PrivatePage_Login? &userGroups=Administrator,Editor,Media]] - Directory.html page

So when I login using a username and password linked to the Editor User Group, I can see both pages but when I login using a username and password from the Media User Group I can only see the Directory.html Page.

The &postHooks=PrivatePage_Login_Redirect parameter in the Login snippet on my Login.html page, picks up on the User Group and Redirects them to the appropriate page. I had to create a snippet for this postHook. As you can see above, I called it PrivatePage_Login_Redirect

Here is the snippet:

<?php
if($_REQUEST['service']=='login'){
    $redirs['Editor'] = '190';
    $redirs['Media'] = '191';
    
    $user = $modx->getObject('modUser', array('username' => $hook->getValue('username')));
    
    foreach ($redirs as $group => $id){
      if ($user->isMember($group)){
          $url=$modx->makeUrl($id);
          $modx->sendRedirect($url);
      }
    }
  }
  return true;

All that together allowed me to create a User who only has access to certain pages. I then created snippets that picked up on the UserGroup and added a Navigation to the top of the page depending on the User.

I tried doing this with Wayfinder but it never worked right. It kept showing both pages in the navigation even if you didn’t have permission. Is there anyway of sorting this? Could anyone help with this? I’d be great to use Wayfinder where it picks up on the User Group and only shows pages for that User.

Anyways, I hope all above helps and if I can sortt the Wayfinder issue, I’ll add it in.

I think the Personalize Extra could help you out with showing different chunks (menus) to different usergroups.

Looks great. Thanks for posting that. :grinning:

Have you ever done this with Wayfinder @bobray? Everytime I try to use Wayfinder, it shows all resources in the wayfinder tree even though the user group doesn’t have permission. The user still gets sent to the error page when trying to click on the page they don’t have access to.

I’d love to be able to use wayfunder where they hide pages a user group has no access to.

You could also place two different Wayfinder calls in separate chunks within separate categories and control the visibility through Element Category ACL entries like mentioned by Bob here (and worked greeat for me):

I got it working. I found this comment from the old community

Ok, got it!! It was a caching issue (Thanks Paulp) it was a combination of setting the wayfinder cacheResults to 0, and unclick the “Cacheable” option on the individual documents “settings” tab. Thanks for all your help everyone.

It works!!!

1 Like

I’ve another question to add to work I’ve finished to date. I never noticed this until today. I was certain it was working before but I guess not.

I have set up an unauthorized page (it’s my login page). I want unauthorized users to be redirected to this page when trying to access a page that they don’t have permission for.

But when I try opening a URL (Authorized Permissions Only) as Anonymous, it doesn’t redirect me to the Unauthorized Page (the Login page), it just has a message on the screen:

Error 404
# Page not found
The page you requested was not found

Is there something I’m missing?

Anonymous user must have “load” permission to the resource group to get a 401 (unauthorized) response.

Thanks a million for that. I got part of it working. I have 2 Contexts (web and eng). Under Access Controls, I gave the (anonymous) user group a Context Access of web, Member - 9999, Load Only and eng, Member - 9999, Load Only. Then, under Resource Group Access, I gave it access to every resource group (I have 3 - Editor, Media and Member) I have with web, Member - 9999, Load Only and eng, Member - 9999, Load Only. I flushed permissions and cleared the cache.

So an unauthorized user who now tries to go on a Permissions page on web, gets redirected to the Unauthorized page. That’s great! But I still have the same issue with the eng Context. I keep getting the 404 error like before.

Have you ever come across this?

did you setup a unauthorized page for the en - context and have set the appropriate context-setting?

I hadn’t as I didn’t know that I needed one for each context. After looking into it, I found that when I changed the Allow Forwarding Across Contxts from NO to YES in Systems Settings, it fixed my problem.

I’m learning everyday and I have you all to thank so Thank You.