Hi all,
First of all, I just wanted to say that I’m new to MODx and it’s been a great experience so far looking at the architecture/model of Revolution - it really is an exciting development environment.
But now I’m stumbling into this issue - when I’m trying to create a simple plugin for authenticating to external system.
Basically what I’m trying to do is to use ’OnBeforeWebLogin’ event which is called indirectly by Login (
http://svn.modxcms.com/docs/display/ADDON/Login+Snippet) snippets/package - to call my own snippets that does the external authentication.
The plugin code is shown below.
<?php
/* Handle event */
switch ($modx->event->name) {
case 'OnBeforeWebLogin':
$username = '';
$givenPassword = '';
if (isset($scriptProperties['username'])) {
/* if exist, assign value */
$username = $scriptProperties['username'];
} else if (isset($scriptProperties['password'])) {
/* if exist, assign value */
$givenPassword = $scriptProperties['password'];
}
// call snippet to do external authentication
$output = $modx->runSnippet('ExternalLogin',$scriptProperties);
// output would be in boolean to test the authentication
// true - would proceed logging into modx
// false - would stop the login into the system
// issue - $modx->event->output((bool) true) -> converting the boolean into integer, which makes it never validates as true
$modx->event->output($output)
break;
case 'OnBeforeWebLogout':
// ... has not been implemented
break;
default: break;
}
return true;
?>
What I intend to do is to have the result from my snippet returning boolean value which would proceed with standard modx login (implemented by Login snippet - package) when the value is true..
but I’m suspecting that there is some issues with
$modx->event->output function. I always get the same results no matter what the boolean value I use, whether true/false.
/core/model/modx/processors/security/Login.php
$rt = false; /* $rt will be an array if the event fires */
if ($loginContext == 'mgr') {
$rt = $modx->invokeEvent("OnBeforeManagerLogin", $onBeforeLoginParams);
} else {
$rt = $modx->invokeEvent("OnBeforeWebLogin", $onBeforeLoginParams);
}
/* If the event fired, loop through the event array and fail if there's an error message */
if (is_array($rt)) {
foreach ($rt as $key => $value) { /* php4 compatible */
if ($value !== true) {
// - my comment - it stops in here everytime
return $modx->error->failure($value);
}
}
unset($key,$value);
}
// - my comment - i need the code to continue on trough here if boolean value true returned
I ran few simple tests - inspecting
/core/model/modx/processors/security/Login.php - and it seems the variable
$value in
$rt returns array if I pass an array to it, returns string if we passed string to it - but it does not return boolean, infact it seems like it is converting the boolean value into integer. So this conditional statement
($value !== true) would always evalute to true - which then stopping the process in that conditional statement each time. Is this meant to happen?
or this is a fault/bug? - I’m unsure how to solve this problem. If the fault is in my approach to create the plugin, could someone in here please point me into the right direction.
Here’s my server info:
- MODx Revolution 2.0.0-rc-2 rev6923
- PHP Version 5.2.5
- Zend engine (phpinfo)
Zend Engine v2.2.0,
with the ionCube PHP Loader v3.1.32, and
with Zend Extension Manager v1.2.2,
with Zend Optimizer v3.3.3,
Thanks very much