if ($params === false) {
//return an error message, the REST params doesn't match with the web service description
}
+
+/// Authentication process
+/// TODO: this use a fake token => need to implement token generation
+ $token = optional_param('token',null,PARAM_ALPHANUM);
+ if (empty($token)) {
+ if ($functionname != 'tmp_get_token') {
+ throw new moodle_exception('identifyfirst');
+ } else {
+ if (optional_param('username',null,PARAM_ALPHANUM) == 'admin' && optional_param('password',null,PARAM_ALPHANUM) == 'admin') {
+ return '465465465468468464';
+ } else {
+ throw new moodle_exception('wrongusernamepassword');
+ }
+ }
+ } else {
+ if (!mock_check_token($token)) {
+ throw new moodle_exception('wrongidentification');
+ }
+ }
+
$res = call_user_func_array ( $classname.'::'.$functionname, array($params));
///Transform result into xml in order to send the REST response
return "<Result>$return</Result>";
}
+/**
+ * TODO: remove this funcion once token implementation is done
+ * Mock function waiting for token system implementation
+ * @param <type> $token
+ * @return <type>
+ */
+function mock_check_token($token) {
+ if ($token == 465465465468468464) {
+ return true;
+ } else {
+ return false;
+ }
+}
/**
*
var_dump($data);
+//we are asking for a token
+$connectiondata['username'] = 'admin';
+$connectiondata['password'] = 'admin';
+$ch = curl_init();
+curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+curl_setopt($ch, CURLOPT_POST, 1);
+curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+$token = curl_exec($ch);
+$data['token'] = $token;
+
curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_create_user');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
<?php
if ($username) {
+
+ //we are asking for a token
+ $connectiondata['username'] = 'admin';
+ $connectiondata['password'] = 'admin';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+ $token = curl_exec($ch);
+ $data['token'] = $token;
+
$data['username'] = $username;
$data['mnethostid'] = $mnethostid;
var_dump($CFG->serverurl.'/user/tmp_get_users');
+
+ //we are asking for a token
+ $connectiondata['username'] = 'admin';
+ $connectiondata['password'] = 'admin';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+ $token = curl_exec($ch);
+ $data['token'] = $token;
+
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_users');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
<?php
if ($username) {
+
+ //we are asking for a token
+ $connectiondata['username'] = 'admin';
+ $connectiondata['password'] = 'admin';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+ $token = curl_exec($ch);
+ $data['token'] = $token;
+
$data['username'] = $username;
$data['mnethostid'] = $mnethostid;
$data['newusername'] = $newusername;