Skip to content

Commit

Permalink
webservice MDL-21351
Browse files Browse the repository at this point in the history
Manage token page: user should be linked to their user profil
Security keys page: display token created by administrator
Manage service page: rewording :
Authorised user only => user
  • Loading branch information
mouneyrac committed Feb 12, 2010
1 parent 1762a26 commit 1bd0650
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lang/en_utf8/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$string['addservice'] = 'Add a new service: $a->name (id: $a->id)';
$string['addaservice'] = 'Add service';
$string['actwebserviceshhdr'] = 'Active web service protocols';
$string['allusers'] = 'All users';
$string['apiexplorer'] = 'API explorer';
$string['apiexplorernotavalaible'] = 'API explorer not available yet.';
$string['arguments'] = 'Arguments';
Expand Down Expand Up @@ -117,6 +118,8 @@
$string['testwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Use an enabled protocol with token authentication. <strong>Warning: the functions that you test WILL BE EXECUTED, be carefull what you choose to test!!!</strong>';
$string['token'] = 'Token';
$string['tokenauthlog'] = 'Token authentication';
$string['tokencreatedbyadmin'] = 'Can only be reset by administrator (*)';
$string['tokencreatedbyadminhelp'] = '(*) Tokens are generally automatically created when you first visit this page. However an administrator could create a token for you. In this special case the token can only be reset by the administrator.';
$string['validuntil'] = 'Valid until';
$string['userasclients'] = 'Users as clients with token';
$string['userasclientsdescription'] = 'The following steps help you to set up the Moodle web service for users as clients. These steps also help to set up the recommended token (security keys) authentication method. In this use case, the user will generate his token from his <strong>Security keys</strong> profile page.';
Expand Down
14 changes: 9 additions & 5 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6218,7 +6218,7 @@ public function output_html($data, $query='') {
$strplugin = get_string('plugin', 'admin');
$stradd = get_string('add');
$strfunctions = get_string('functions', 'webservice');
$strusers = get_string('restrictedusers', 'webservice');
$strusers = get_string('users');
$strserviceusers = get_string('serviceusers', 'webservice');

$esurl = "$CFG->wwwroot/$CFG->admin/webservice/service.php";
Expand Down Expand Up @@ -6258,7 +6258,7 @@ public function output_html($data, $query='') {
if ($service->restrictedusers) {
$users = "<a href=\"$euurl?id=$service->id\">$strserviceusers</a>";
} else {
$users = '-';
$users = get_string('allusers', 'webservice');
}

$edit = "<a href=\"$esurl?id=$service->id\">$stredit</a>";
Expand Down Expand Up @@ -6299,7 +6299,7 @@ public function output_html($data, $query='') {
if ($service->restrictedusers) {
$users = "<a href=\"$euurl?id=$service->id\">$strserviceusers</a>";
} else {
$users = '-';
$users = get_string('allusers', 'webservice');
}

$edit = "<a href=\"$esurl?id=$service->id\">$stredit</a>";
Expand Down Expand Up @@ -6789,7 +6789,7 @@ public function output_html($data, $query='') {
//TODO: in order to let the administrator delete obsolete token, split this request in multiple request or use LEFT JOIN

//here retrieve token list (including linked users firstname/lastname and linked services name)
$sql = "SELECT t.id, t.token, u.firstname, u.lastname, s.name, t.validuntil
$sql = "SELECT t.id, t.token, u.id AS userid, u.firstname, u.lastname, s.name, t.validuntil
FROM {external_tokens} t, {user} u, {external_services} s
WHERE t.creatorid=? AND t.tokentype = ? AND s.id = t.externalserviceid AND t.userid = u.id";
$tokens = $DB->get_records_sql($sql, array($USER->id, EXTERNAL_TOKEN_PERMANENT));
Expand All @@ -6814,7 +6814,11 @@ public function output_html($data, $query='') {
$iprestriction = $token->iprestriction;
}

$table->data[] = array($token->token, $token->firstname." ".$token->lastname, $token->name, '', $iprestriction, $validuntil, $delete);
$userprofilurl = new moodle_url('/user/view.php?id='.$token->userid);
$useratag = html_writer::start_tag('a', array('href' => $userprofilurl));
$useratag .= $token->firstname." ".$token->lastname;
$useratag .= html_writer::end_tag('a');
$table->data[] = array($token->token, $useratag, $token->name, '', $iprestriction, $validuntil, $delete);
}

$return .= $OUTPUT->table($table);
Expand Down
13 changes: 10 additions & 3 deletions user/managetoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@

//here retrieve token list (including linked users firstname/lastname and linked services name)
$sql = "SELECT
t.id, t.token, u.firstname, u.lastname, s.name, t.validuntil
t.id, t.creatorid, t.token, u.firstname, u.lastname, s.name, t.validuntil
FROM
{external_tokens} t, {user} u, {external_services} s
WHERE
t.creatorid=? AND t.tokentype = ".EXTERNAL_TOKEN_PERMANENT." AND s.id = t.externalserviceid AND t.userid = u.id";
t.userid=? AND t.tokentype = ".EXTERNAL_TOKEN_PERMANENT." AND s.id = t.externalserviceid AND t.userid = u.id";
$tokens = $DB->get_records_sql($sql, array( $USER->id));
if (!empty($tokens)) {
foreach ($tokens as $token) {
Expand All @@ -156,10 +156,17 @@
$validuntil = date("F j, Y"); //TODO: language support (look for moodle function)
}

if ($token->creatorid != $USER->id) {
$reset = get_string('tokencreatedbyadmin', 'webservice');
$admintokeninfo = get_string('tokencreatedbyadminhelp', 'webservice');
}
$table->data[] = array($token->token, $token->name, $validuntil, $reset);
}

$return .= $OUTPUT->table($table);
if (!empty($admintokeninfo)) {
$return .= $admintokeninfo;
}
} else {
$return .= get_string('notoken', 'webservice');
}
Expand Down

0 comments on commit 1bd0650

Please sign in to comment.