Using SOAP API to log in or create new users no longer working after update to 2.9

Using SOAP API to log in or create new users no longer working after update to 2.9

by Sean Kimball -
Number of replies: 0

Using SOAP API to log in or create new users no longer working after update to 2.9 - no idea what's wrong [I didn't do the update] 

I'm using an SSO script to either authenticate a moodle user or create them if they don't exist. It does work, but I'm getting errors back from the webservice that are not helpful:

Here is the debugging excerpt from the modx logs [the system that initiates the login}


[2015-08-10 23:10:27] (ERROR @ /index.php) Modx user newmoodleuser authenticated, attempting moodle login.

[2015-08-10 23:10:27] (ERROR @ /index.php) Modx user QCd+xxxxxxxxxxx= checking modx groups

[2015-08-10 23:10:27] (ERROR @ /index.php) newmoodleuser | !password99 running function getMoodleUser.

[2015-08-10 23:10:27] (ERROR @ /index.php) newmoodleuser query rows fetched 0

[2015-08-10 23:10:27] (ERROR @ /index.php) newmoodleuser query results <pre>1</pre>

[2015-08-10 23:10:27] (ERROR @ /index.php) newmoodleuser num == 0

[2015-08-10 23:10:27] (ERROR @ /index.php)  running function getMoodleEmail.

[2015-08-10 23:10:27] (ERROR @ /index.php)  Moodle email not found

[2015-08-10 23:10:27] (ERROR @ /index.php) Modx user newmoodleuser successfully authenticated but was NOT found in moodle - creating moodle user!

[2015-08-10 23:10:27] (ERROR @ /index.php) Creating: username = newmoodleuser password = !password99 user token = xxxxxxxxxxx userdomain = http://cme.domain.com

[2015-08-10 23:10:27] (ERROR @ /index.php) newmoodleuser running function createMoodleUser.

[2015-08-10 23:10:27] (ERROR @ /index.php)  running function createMoodleUserNames.

[2015-08-10 23:10:27] (ERROR @ /index.php)  created moodle user first and last names: Array

(

    [0] => First

    [1] =>  last

)


[2015-08-10 23:10:28] (ERROR @ /index.php) There was an error creating a new user in moodle, user = newmoodleuser exception = SoapFault exception: [Receiver] Invalid parameter value detected | ERRORCODE: invalidparameter in /var/www/vhosts/domain.com/core/cache/includes/elements/modplugin/15.include.cache.php:646

Stack trace:

#0 /var/www/vhosts/domain.com/core/cache/includes/elements/modplugin/15.include.cache.php(646): SoapClient->__soapCall('core_user_creat...', Array)

#1 /var/www/vhosts/domain.com/core/cache/includes/elements/modplugin/15.include.cache.php(747): createMoodleUser('newmoodleuser', '!password99', 'xxxxxxxx...', 'http://cme.doma...')

#2 /var/www/vhosts/domain.com/core/model/modx/modscript.class.php(70): include('/var/www/vhosts...')

#3 /var/www/vhosts/domain.com/core/model/modx/modx.class.php(1612): modScript->process(Array)

#4 /var/www/vhosts/domain.com/core/model/modx/processors/security/login.php(192): modX->invokeEvent('OnWebLogin', Array)

#5 /var/www/vhosts/domain.com/core/model/modx/modprocessor.class.php(343): include('/var/www/vhosts...')

#6 /var/www/vhosts/domain.com/core/model/modx/modprocessor.class.php(173): modDeprecatedProcessor->process()

#7 /var/www/vhosts/domain.com/core/model/modx/modx.class.php(1701): modProcessor->run()

#8 /var/www/vhosts/domain.com/core/components/login/controllers/web/Login.php(248): modX->runProcessor('security/login', Array)

#9 /var/www/vhosts/domain.com/core/components/login/controllers/web/Login.php(182): LoginLoginController->runLoginProcessor()

#10 /var/www/vhosts/domain.com/core/components/login/controllers/web/Login.php(161): LoginLoginController->login()

#11 /var/www/vhosts/domain.com/core/components/login/controllers/web/Login.php(67): LoginLoginController->handleRequest()

#12 /var/www/vhosts/domain.com/core/components/login/model/login/logincontroller.class.php(59): LoginLoginController->process()

#13 /var/www/vhosts/domain.com/core/cache/includes/elements/modsnippet/8.include.cache.php(57): LoginController->run(Array)

#14 /var/www/vhosts/domain.com/core/model/modx/modscript.class.php(70): include('/var/www/vhosts...')

#15 /var/www/vhosts/domain.com/core/model/modx/modparser.class.php(513): modScript->process('&preHooks=`mood...')

#16 /var/www/vhosts/domain.com/core/model/modx/modparser.class.php(247): modParser->processTag(Array, true)

#17 /var/www/vhosts/domain.com/core/model/modx/modresponse.class.php(83): modParser->processElementTags('', '<!DOCTYPE html>...', true, false, '', '', Array, 10)

#18 /var/www/vhosts/domain.com/core/model/modx/modrequest.class.php(145): modResponse->outputContent(Array)

#19 /var/www/vhosts/domain.com/core/model/modx/modrequest.class.php(129): modRequest->prepareResponse()

#20 /var/www/vhosts/domain.com/core/model/modx/modx.class.php(1404): modRequest->handleRequest()

#21 /var/www/vhosts/domain.com/httpdocs/index.php(72): modX->handleRequest()

#22 {main}

[2015-08-10 23:10:28] (ERROR @ /index.php) There was an error creating a new user in moodle, user = newmoodleuser params = Array

(

    [0] => stdClass Object

        (

            [username] => newmoodleuser

            [password] => !password99

            [firstname] => first

            [lastname] =>  last

            [email] => dave@hotpocket.com

            [auth] => manual

            [idnumber] => 5396

            [lang] => en

            [theme] => standard

            [timezone] => 99

            [mailformat] => 0

            [description] =>

            [city] => oshawa

            [country] => CA

        )


)




So the:


[2015-08-10 23:10:28] (ERROR @ /index.php) There was an error creating a new user in moodle, user = newmoodleuser exception = SoapFault exception: [Receiver] Invalid parameter value detected | ERRORCODE: invalidparameter in /var/www/vhosts/domain.com/core/cache/includes/elements/modplugin/15.include.cache.php:646


is the line saying WHAT the problem is but not SPECIFICALLY what parameter is invalid? or why? 

so here is the function I am using to create the account:


/*

*

* Function to create moodle user

*

*/

function createMoodleUser($username,$password,$musertoken,$muserdomain){

global $modx;

$debug = $modx->config['moodlesso_debug']; 

if($debug){$modx->log(modX::LOG_LEVEL_ERROR, $username.' running function createMoodleUser.');}

$countries = array("AF"=>"AFGHANISTAN", 

"AX"=>"ALAND ISLANDS", 

...etc...

"ZW"=>"ZIMBABWE"); 

  $functionname = 'core_user_create_users';

// create params

$moduser = $modx->getObject('modUser', array('username'=>$username));

  $moduserid = $moduser->get('id');

$profile = $moduser->getOne('Profile');

$email = $profile->get('email');

$fullname = $profile->get('fullname');


$city = $profile->get('city');

//$country = $profile->get('country');

$comment = $profile->get('comment');


 

// split the modx full names into first & last names.

  $fullname = (!isset($fullname) || is_null($fullname) || strlen($fullname) == 0) ? 'Guest User' : $fullname;

$names = createMoodleUserNames(str_replace(' ','_',$fullname));

$firstname = $names[0];

$lastname = $names[1];

/* find the country abbreviation

if (array_search(strtolower($country), array_map('strtolower', $countries))){

$country = array_search(strtolower($myvar), array_map('strtolower', $countries));

}else{

$country = 'CA';

}

  */

$user = new stdClass();

$user->username = $username;

$user->password = $password;

$user->firstname = $firstname;

$user->lastname = $lastname;

$user->email = $email;

$user->auth = 'manual';

$user->idnumber = $moduserid;

$user->lang = 'en';

$user->theme = 'standard';

$user->timezone = '99';

$user->mailformat = 0;

$user->description = $comment;

$user->city = $city;

$user->country = 'CA';

$params = array($user);


// SOAP CALL

$serverurl = $muserdomain . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $musertoken;

 

// Do the main soap call

$client = new SoapClient($serverurl);

try {

$resp = $client->__soapCall($functionname, array($params));

} catch (Exception $e) {



 

 //$errparams = print_r($params,1);

 $modx->log(modX::LOG_LEVEL_ERROR, 'There was an error creating a new user in moodle, user = '.$username.' exception = '.$e);

 $modx->log(modX::LOG_LEVEL_ERROR, 'There was an error creating a new user in moodle, user = '.$username.' params = '. print_r($params, TRUE) );

 $modx->log(modX::LOG_LEVEL_ERROR, 'There was an error creating a new user in moodle, user = '.$username.' params = '.  $serverurl);


// send some mail for failed user creation attempts

$message = '';

$message .= '<p>An error has occured adding a Modx user to the Moodle database, the exception & username is listed below. Check the modx logs for more information</p>';

$message .= 'Username = '.$username;

  $message .= '<pre>'.$errparams.'</pre>';

$message .= '<pre>';

$message .= $e;

$message .= '</pre>';

$toemail = $modx->config['moodlesso_mailerrorto']; 

$ccemail = $modx->config['moodlesso_mailerrorcc']; 


$modx->getService('mail', 'mail.modPHPMailer');

$modx->mail->set(modMail::MAIL_BODY,$message);

$modx->mail->set(modMail::MAIL_FROM,'sso@oncologyeducation.com');

$modx->mail->set(modMail::MAIL_FROM_NAME,'SSO Webservice ');

$modx->mail->set(modMail::MAIL_SENDER,'SSO');

$modx->mail->set(modMail::MAIL_SUBJECT,'Moodle SSO error');

$modx->mail->address('to',$toemail);

$modx->mail->address('cc',$ccemail);

$modx->mail->address('reply-to','no-reply@oncologyeducation.com');

$modx->mail->setHTML(true);

if (!$modx->mail->send()) {

$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send email from the CME SSO extra: '.$modx->mail->mailer->ErrorInfo);

  $userstring = print_r($params,1);

       $modx->log(modX::LOG_LEVEL_ERROR,'Athe user params were: <pre>'.$userstring.'</pre>');

}

$modx->mail->reset();

return false;

}

if (isset($resp)) {

  //echo 'response got'.$resp;

if($debug){$modx->log(modX::LOG_LEVEL_ERROR, 'User '.$username.' created successfully in moodle');}

return true;

}

 

}





so, what can I do to troubleshoot this further? All I need to know is which parameter is "invalid"  Like I said this USED to work perfectly iut just stopped after the update. 

Average of ratings: -