简体   繁体   中英

Moodle API create user, generate password and email user

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM