简体   繁体   English

Moodle API创建用户,生成密码和电子邮件用户

[英]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. 我正在尝试通过Web服务API(版本2.7.1+(内部版本:20140829)在Moodle中创建一个新用户。我想自动生成密码,并通过电子邮件将其新帐户通知用户。

When I create a user via GUI there is a checkbox for doing exactly that: generating password and notifying user via email. 当我通过GUI创建用户时,有一个复选框可以做到这一点:生成密码并通过电子邮件通知用户。

在此处输入图片说明

However, when I create a user via the API I do not know how to force password generation and the email notification. 但是,当我通过API创建用户时,我不知道如何强制生成密码和电子邮件通知。 Unfortunately I cannot find anything in the Moodle API about how to automatically send email after user creation. 不幸的是,我在Moodle API中找不到有关如何在用户创建后自动发送电子邮件的任何信息。

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: 这似乎是在https://moodle.org/mod/forum/discuss.php?d=323422上问的相同问题,所以这里是相同的答案:

"this improvement was introduced in 3.0, you may be interested in MDL-51182 , it seems simple to backport." “此改进是在3.0中引入的,您可能对MDL-51182感兴趣 ,似乎很容易向后移植。”

Kind regards, Daniel 亲切的问候,丹尼尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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