Update README.md
This commit is contained in:
parent
7e39fab83f
commit
f8a1df93cf
1 changed files with 15 additions and 12 deletions
27
README.md
27
README.md
|
@ -96,10 +96,12 @@ E.g. http://yourmoodle.com/login/index.php?enrolkey_skipsso=1
|
||||||
|
|
||||||
**Example client**
|
**Example client**
|
||||||
|
|
||||||
The code below defines a function that can be used to obtain a login url.
|
**Note:** the code below is not for production use. It's just a quick and dirty way to test the functionality.
|
||||||
You will need to add/remove parameters depending on whether you have iprestriction or update/create user enabled and which mapping field you are using.
|
|
||||||
|
|
||||||
The required library curl.php can be obtained from https://github.com/dongsheng/cURL
|
The code below defines a function that can be used to obtain a login url.
|
||||||
|
You will need to add/remove parameters depending on whether you have update/create user enabled and which mapping field you are using.
|
||||||
|
|
||||||
|
The required library curl can be obtained from https://github.com/moodlehq/sample-ws-clients
|
||||||
```php
|
```php
|
||||||
/**
|
/**
|
||||||
* @param string $useremail Email address of user to create token for.
|
* @param string $useremail Email address of user to create token for.
|
||||||
|
@ -112,8 +114,8 @@ The required library curl.php can be obtained from https://github.com/dongsheng/
|
||||||
* @param int $activityid cmid to send logged in users to, defaults to site home.
|
* @param int $activityid cmid to send logged in users to, defaults to site home.
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
function getloginurl($useremail, $firstname, $lastname, $username, $ipaddress, $courseid = null, $modname = null, $activityid = null) {
|
function getloginurl($useremail, $firstname, $lastname, $username, $courseid = null, $modname = null, $activityid = null) {
|
||||||
require_once('./curl.php');
|
require_once('curl.php');
|
||||||
|
|
||||||
$token = 'YOUR_TOKEN';
|
$token = 'YOUR_TOKEN';
|
||||||
$domainname = 'http://MOODLE_WWW_ROOT';
|
$domainname = 'http://MOODLE_WWW_ROOT';
|
||||||
|
@ -121,21 +123,22 @@ function getloginurl($useremail, $firstname, $lastname, $username, $ipaddress, $
|
||||||
|
|
||||||
$param = [
|
$param = [
|
||||||
'user' => [
|
'user' => [
|
||||||
'firstname' => $firstname,
|
'firstname' => $firstname, // You will not need this parameter, if you are not creating/updating users
|
||||||
'lastname' => $lastname,
|
'lastname' => $lastname, // You will not need this parameter, if you are not creating/updating users
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'email' => $useremail,
|
'email' => $useremail,
|
||||||
'ip' => $ipaddress
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname . '&moodlewsrestformat=json';
|
$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname . '&moodlewsrestformat=json';
|
||||||
$curl = new curl;
|
$curl = new curl; // The required library curl can be obtained from https://github.com/moodlehq/sample-ws-clients
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$resp = $curl->post($serverurl, $param);
|
$resp = $curl->post($serverurl, $param);
|
||||||
$resp = json_decode($resp);
|
$resp = json_decode($resp);
|
||||||
$loginurl = $resp->loginurl;
|
if ($resp && !empty($resp->loginurl)) {
|
||||||
|
$loginurl = $resp->loginurl;
|
||||||
|
}
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +158,7 @@ function getloginurl($useremail, $firstname, $lastname, $username, $ipaddress, $
|
||||||
return $loginurl . $path;
|
return $loginurl . $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo getloginurl('barrywhite@googlemail.com', 'barry', 'white', 'barrywhite', '127.0.0.1', 2, 'certificate', 8);
|
echo getloginurl('barrywhite@googlemail.com', 'barry', 'white', 'barrywhite', 2, 'certificate', 8);
|
||||||
```
|
```
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
Loading…
Reference in a new issue