Reputation: 2279
I am trying to create a new user in Moodle via the Web service API (version 2.7.1+ (Build: 20140829). I want to auto-generate the password and notify the user via email about his new account.
When I create a user via GUI there is a checkbox for doing exactly that: generating password and notifying user via email.
However, when I create a user via the API I do not know how to force password generation and the email notification. Unfortunately I cannot find anything in the Moodle API about how to automatically send email after user creation.
private function createUser($firstName, $lastName, $email){
$newUser = new stdClass();
$newUser->username = strtolower($email);
$newUser->password = getInitialPassword();
$newUser->firstname = $firstName ?: getRandomUsername();
$newUser->lastname = $lastName ?: '.';
$newUser->email = $email;
$newUser->preferences = array(array('type' =>'auth_forcepasswordchange', 'value' => true));
$users = array($newUser);
$params = array('users' => $users);
return post(buildServerUrl($create_user_command), $params);
}
Does anyone know how to do that?
Upvotes: 1
Views: 3743
Reputation: 89
it seems to be the same question asked at https://moodle.org/mod/forum/discuss.php?d=323422 , so here is the same answer:
"this improvement was introduced in 3.0, you may be interested in MDL-51182, it seems simple to backport."
Kind regards, Daniel
Upvotes: 2