This question has been answered by gadgetto. See the first response.
MODX Documentation - see Security
MODX Add On's - See Login, Register, DefaultResourceGroup, DefaultUserGroup - and any other registration & login Extras such as Frontpage, NewsPublisher, etc. See also the documentation for these at http://rtfm.modx.com/display/ADDON/Home
Bob's Guides - http://bobsguides.com - See the MODX Security information
Beware, don't just start adding context ACL's and user groups till you've got a decent handle on all the documentation. Even then, expect to make mistakes. It's not exactly simple. Post here if you have questions.
Interesting that no one has a clue of how to do this.
Now I'm skipping modx's security part all along and have added my own script to see if the correct session variable exists or not on each page that is loaded.
So in the modx manager all pages are public but the ones I want private has the script. Feels like extra work and not safe, but it works.
Quote from: phacer at Nov 20, 2012, 09:17 AMInteresting that no one has a clue of how to do this.
Now I'm skipping modx's security part all along and have added my own script to see if the correct session variable exists or not on each page that is loaded.
So in the modx manager all pages are public but the ones I want private has the script. Feels like extra work and not safe, but it works.
You should have a look at the Login (http://modx.com/extras/package/login) extra - I think it should do what you want!
Or you could use the MODx API to receive login status of a user:
http://api.modx.com/revolution/2.2/ - core/model/modx/moduser.class.php
If you would like to show visitors a menu entry but not let them open the resource without logging in, you have to give the special user group (anonymous) load and list access to the resource group of these menu entries.
greetings,
Martin
<?php
$loginContext = isset($_REQUEST['login_context']) && !empty($_REQUEST['login_context']) ? $_REQUEST['login_context'] : $modx->context->get('key');
$contexts = !empty($scriptProperties['contexts']) ? $scriptProperties['contexts'] : '';
$contexts = !empty($_REQUEST['add_contexts']) ? $_REQUEST['add_contexts'] : $contexts;
$authenticated = $modx->user->isAuthenticated($loginContext);
if (!$authenticated) {
// get the username and password in a way that fits your snippet
$_POST['username'] = $username;
$_POST['password'] = $password;
if (!isset($_POST['login_context'])) $_POST['login_context'] = $loginContext;
$response = $modx->executeProcessor(array(
'action' => 'login',
'location' => 'security',
'login_context' => $loginContext,
'add_contexts' => $contexts,
'rememberme' => !empty($_REQUEST['rememberme']) ? true : false,
));
if (empty($response['success']) ) {
// code to handle unhappy user
} else {
// code to handle happy user
}
}
Here is a sample code for loggin in a user via API (I think it's originally from Jason Coward):
<!--?php $loginContext = isset($_REQUEST['login_context']) && !empty($_REQUEST['login_context']) ? $_REQUEST['login_context'] : $modx--->context->get('key'); $contexts = !empty($scriptProperties['contexts']) ? $scriptProperties['contexts'] : ''; $contexts = !empty($_REQUEST['add_contexts']) ? $_REQUEST['add_contexts'] : $contexts; $authenticated = $modx->user->isAuthenticated($loginContext); if (!$authenticated) { // get the username and password in a way that fits your snippet $_POST['username'] = $username; $_POST['password'] = $password; if (!isset($_POST['login_context'])) $_POST['login_context'] = $loginContext; $response = $modx->executeProcessor(array( 'action' => 'login', 'location' => 'security', 'login_context' => $loginContext, 'add_contexts' => $contexts, 'rememberme' => !empty($_REQUEST['rememberme']) ? true : false, )); if (empty($response['success']) ) { // code to handle unhappy user } else { // code to handle happy user } }
If you try to execute this code from "outside" of MODx you first need to get a connection to MODx:
- this can be done through a snippet which is called in a MODx resource
- or by including the necessary MODx files in your php file (please have a look at the forums, this was postet many times before)
require_once 'config.core.php';
require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');