Quote from: BobRay at Aug 10, 2008, 02:37 PM
That will be great. While you’re at it, you might consider changing the names of some of the files. There are a number of different login.php and login.js files. The one that actually does the authentication tests might better be called something like loginproc.php. Some comments at the beginning about who calls us and what we do wouldn’t hurt either.
Does this make sense? Pull the actual authentication tests out of loginproc.php and make it an object with a "register authentication" method that lets people register as many authentification techniques as they like, each with test code, a failure message, and a priority number (to determine what order the tests are made).
The location of the files determines what purpose they serve; it makes more sense to me to keep the various parts of the same feature in files of the same name at the appropriate location. With that in mind, you are talking about the login processor in the model, i.e. core/model/modx/processors/security/login.php, which provides a single interface for login supported by a plugin event framework for external authentication, as well as the option for providing derivative modUser classes to extend/override just about any part of user behavior, and configure them by Context.
If some of the functionality in this login processor needs to be refactored and moved into a plugin, or additional configuration settings need to be added, we can do that. If we need a new event, we can do that (though I think we have plenty in there), etc.
We can already give plugins a priority, so it shouldn’t be a problem doing that. Ultimately, I think everything we need is there, users can provide their own custom processors, their own custom authentication plugins, and much more.
I’ll review it some more, but in the meantime, here is an example plugin for simple authentication/user integration with Crowd (via SOAP) I already have working; I’ll be releasing more of this component very soon, along with the new MODx web site infrastructure built on Revolution.
<?php
switch ($modx->event->name) {
case "OnUserNotFound":
if (isset($username) && !empty($username)) {
$crowdAttributes = array (
'url' => isset($crowdUrl) ? $crowdUrl : $modx->config['user.crowd.url'],
'application' => isset($crowdApp) ? $crowdApp : $modx->config['user.crowd.application'],
'credential' => isset($crowdPwd) ? $crowdPwd : $modx->config['user.crowd.credential']
);
$modx->addPackage('modx.user.crowd', MODX_CORE_PATH . 'model/');
if ($crowd = $modx->getService('crowd', 'modCrowdClient', '', $crowdAttributes)) {
$userexists = $crowd->findUsername($username);
$user = & $scriptProperties['user'];
$user = $modx->newObject('modCrowdUser');
$user->set('username', $username);
$user->addOne($modx->newObject('modUserProfile'));
}
}
break;
//Register this event for authentication in all other contexts
case "OnWebAuthentication":
//Register this event for manager authentication only
case "OnManagerAuthentication":
$authenticated = false;
if (isset($user) && !empty($user) && isset($password) && !empty($password)) {
$crowdAttributes = array (
'url' => isset($crowdUrl) ? $crowdUrl : $modx->config['user.crowd.url'],
'application' => isset($crowdApp) ? $crowdApp : $modx->config['user.crowd.application'],
'credential' => isset($crowdPwd) ? $crowdPwd : $modx->config['user.crowd.credential']
);
$modx->addPackage('modx.user.crowd', MODX_CORE_PATH . 'model/');
if ($crowd = $modx->getService('crowd', 'modCrowdClient', '', $crowdAttributes)) {
if ($authenticated = $crowd->authenticate($user->get('username'), $password)) {
if ($user->isNew() && is_a($user, 'modCrowdUser') && $modx->config['user.crowd.autoadd']) {
if ($userDetails = $crowd->getUser($user->get('username'))) {
$user->modUserProfile->set('fullname', implode(" ", array($userDetails['givenName'], $userDetails['sn'])));
$user->modUserProfile->set('email', $userDetails['mail']);
$user->modUserProfile->set('failed_logins', $userDetails['invalidPasswordAttempts']);
$user->modUserProfile->set('last_login', $userDetails['lastAuthenticated']);
$authenticated = $user->save();
}
}
}
}
}
$modx->event->_output = $authenticated;
break;
}
?>