print_r the value of $rt -- it may be an array...in which case we need to loop through all the plugin results and make sure there aren’t any messages instead of true values.
Yes, consider if you have three different plugins extending the login page; each one returns it’s own result. So you need to make sure each one of them returns true; in other words, if any one of the results in the array are !== true, it’s an error, and potentially a returned message.
I have the plugin working as it should. $rt *is* an array and the value set in the plugin is in $rt[0]. I’m not sure if that’s reliable if other plugins are listening for the same event (which in this case they might be).
This is because we aren’t explicitly providing $captcha_code to the event; this was my comment about using the $_POST variables directly.
The $_SESSION variable set in vericode.php is available in the plugin. The $captcha_code variable isn’t -- I haven’t figured out why -- but $_POST[’captcha_code’] is available so I used that.
All you need to do is add some Smarty variable assignments that can be rendered by the template. e.g.
Now we need a way to inject the captcha field into the form and have it set the $_POST[’captcha_code’] value.
<?php
$modx->smarty->assign('captcha_image', $captcha_image);
$modx->smarty->assign('captcha_input', $captcha_input);
?>
All you need to do is add some Smarty variable assignments that can be rendered by the template. e.g.<?php $modx->smarty->assign('captcha_image', $captcha_image); $modx->smarty->assign('captcha_input', $captcha_input); ?>
You could even use a standard name for all the content rendered by these plugins and simply append content onto one of those variables, i.e. OnBeforeManagerLoginOutput or something... just ideas...
We could put some of these between the existing fields in login.tpl:
{$onManagerLoginFormExtraField1} {$onManagerLoginFormExtraField2}
{$captcha_image}
{$captcha_input}It can be an array or a single result. We’ll have to test for both possibilities.
I have the login.php processor plugin working as it should (although I still need to know whether I can count on the event output being an array -- I’m guessing yes since it comes back as an array when set to a single string or to a boolean value).
I think OnManagerLoginFormPrerender is the proper event and I don’t see any reason it can’t be moved to the proper location in the tpl. Also, I personally think the additional output should be injected by the plugin without overwriting any content that might be injected from other plugins registered to the event. IOW, each plugin should append any output to the same variable or we make the variable an array and do a loop through it, displaying each resulting output between the password field and the rememberme checkbox (replacing the old captcha variables).
Now for the controller login.php and the smarty template.
The $OnManagerLoginFormPrerender variable in the smarty template is in the wrong place for the captcha prompt and image. It doesn’t seem wise to move it.
These guys are in the right place --
{$captcha_image} {$captcha_input}
But if we pull captcha out of the core, they’ll be gone (and there’s no place for the captcha prompt -- which needs to change when using the MathString). We could put a new, more generic, variable there like {$OnLoginSecurityCheck} or something similar, but it should probably have a system event of its own. I could use the OnManagerLoginFormPrerender event to populate it but that seems wrong.
All this has me wondering about the MODx event model which I admit I don’t understand very well. What happens when a user sets up another system event to listen to OnManagerLoginFormPrerender and sends some additional output back? Does it just get appended or prepended to the array that comes back depending on the priority of the event? [[Edit: Yes -- tested it myself].
Also, are there plans to let users create new system events in the Manager?
Quote from: BobRay at Aug 14, 2008, 12:41 AMIt can be an array or a single result. We’ll have to test for both possibilities.
I have the login.php processor plugin working as it should (although I still need to know whether I can count on the event output being an array -- I’m guessing yes since it comes back as an array when set to a single string or to a boolean value).
$results= array (); ... return $results;