Hi Bob - I have been working though these posts ( which are great!)
I am having a problem with this one:
http://bobsguides.com/blog.html/2016/04/09/bypassing-the-modx-manager-login-ii
My code is
<?php
/* Return if the user is already there ($username is already set in this event) */
$existingUser = $modx->getObject('modUser', array ('username' => $username));
if ($existingUser) {
$modx->event->_output = false;
return;
}
/* Generate a random, 50 character password */
$password = "";
for($i=0;$i<50;$i++) {
$password .= chr( (mt_rand(1, 36) <= 26) ? mt_rand(97, 122) : mt_rand(48, 57 ));
}
/* Create the new user */
$fields = array(
'username' => $username,
'password' => $password,
'blocked' => '0',
'email' => '[email protected]',
'passwordnotifymethod' => 'x',
);
$response = $modx->runProcessor('security/user/create', $fields);
if ($response->isError()) {
if ($response->hasFieldErrors()) {
$fieldErrors = $response->getAllErrors();
$errorMessage = implode("\n", $fieldErrors);
} else {
$errorMessage = $response->getMessage();
}
$modx->log(modX::LOG_LEVEL_ERROR, '[OnBeforeManagerLogin] ' . $errorMessage);
$modx->event->_output = true;
return;
}
$modx->event->_output = false;
return;
and i running my plugin on the
onBedforeManagerLogin event - but I am not having any luck!
in my error report I am just getting:
[OnBeforeManagerLogin] Permission denied!
Any idea what I am doing wrong?