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.