Surely locking one page to one user should be simple enough?
[[!MemberPage]]
<?php
/*MemberPage snippet */
/* kick out anonymous users */
if (! $modx->user->hasSessionContext($modx->context->get('key')) ) {
$modx->sendUnauthorizedPage();
}
/* check current id against tree_root_id setting */
if ( $modx->getOption('tree_root_id') != $modx->resource->id) {
$modx->sendUnauthorizedPage();
}
?><?php
/*MemberPages snippet */
/* Allow user to access a page and its children */
/* kick out anonymous users */
if (! $modx->user->hasSessionContext($modx->context->get('key')) ) {
$modx->sendUnauthorizedPage();
}
/* check current id against tree_root_id setting and it's children */
$treeRoot = $modx->getOption('tree_root_id');
$allowed = $modx->getChildIds($treeRoot);
$allowed[] = $treeRoot;
if (! in_array($modx->resource->id,$allowed) ) {
$modx->sendUnauthorizedPage();
}
?>
Quote from: m165 at Jul 28, 2010, 02:28 PM
Surely locking one page to one user should be simple enough?
It should be, and it is in the Manager using the tree_root_id user setting. In the front end, however, I don’t know of a simple solution. You can create a resource group for each resource and a user group for each user as you did in Evolution and connect the two with a resource Group Access ACL entry.
You could also use a snippet on each of the protected pages (or in their template) that checked the tree_root_id setting. Something like this:
[[!MemberPage]]
<?php /*MemberPage snippet */ /* kick out anonymous users */ if (! $modx->user->hasSessionContext($modx->context->get('key')) ) { $modx->sendUnauthorizedPage(); } /* check current id against tree_root_id setting */ if ( $modx->getOption('tree_root_id') != $modx->resource->id) { $modx->sendUnauthorizedPage(); } ?>
To allow users to also access children of the tree_root_id page too, you’d do something like this:
<?php /*MemberPages snippet */ /* Allow user to access a page and its children */ /* kick out anonymous users */ if (! $modx->user->hasSessionContext($modx->context->get('key')) ) { $modx->sendUnauthorizedPage(); } /* check current id against tree_root_id setting and it's children */ $treeRoot = $modx->getOption('tree_root_id'); $allowed = $modx->getChildIds($treeRoot); $allowed[] = $treeRoot; if (! in_array($modx->resource->id,$allowed) ) { $modx->sendUnauthorizedPage(); } ?>
You can add the tree_root_id user setting by going to Security->Manage Users->Update User->Settings tab->Create New. Set the Key to tree_root_id and the Value to the ID of the user’s resource or container. You can use a comma-delimited list of IDs here (with no spaces) to give the user access to multiple parts of the site. If you do that, though, you’ll have to change the code in the snippets above to handle the multiple entries.
Can anything be done in Evolution where you have a manager login that really only should have manager control over one page? I can force them to the page on login but would like to be able to force a manager to auto log out when they leave the page they are assigned to. The public will also be able to view these pages. Any advice is most appreciated.
bauhaus9
Can anything be done in Evolution where you have a manager login that really only should have manager control over one page? I can force them to the page on login but would like to be able to force a manager to auto log out when they leave the page they are assigned to. The public will also be able to view these pages. Any advice is most appreciated.
bauhaus9
Sorry, I’ve been working in Revolution so much that I’m unreliable on Evolution questions.
The only thing that comes to mind is a snippet on every non-manager page that logs off any logged-in user.
if ($modx->userLoggedIn() ) {
/* log user out */
$modx->logout(); // not sure about this.
}