Skip to content

Commit

Permalink
webservice MDL-21351 add creator field to security keys page
Browse files Browse the repository at this point in the history
  • Loading branch information
mouneyrac committed Feb 12, 2010
1 parent 1bd0650 commit b721742
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lang/en_utf8/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
$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['tokencreator'] = 'Creator';
$string['keyshelp'] = 'The keys are used to access your Moodle account from external applications.';
$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
38 changes: 24 additions & 14 deletions user/managetoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@
$stroperation = get_string('operation', 'webservice');
$strtoken = get_string('key', 'webservice');
$strservice = get_string('service', 'webservice');
$struser = get_string('user');
$strcreator = get_string('tokencreator', 'webservice');
$strcontext = get_string('context', 'webservice');
$strvaliduntil = get_string('validuntil', 'webservice');

$return = $OUTPUT->heading(get_string('securitykeys', 'webservice'), 3, 'main', true);
$return .= $OUTPUT->box_start('generalbox webservicestokenui');

$return .= get_string('keyshelp', 'webservice');

$table = new html_table();
$table->head = array($strtoken, $strservice, $strvaliduntil, $stroperation);
$table->align = array('left', 'left', 'left', 'center', 'center');
$table->head = array($strtoken, $strservice, $strvaliduntil, $strcreator, $stroperation);
$table->align = array('left', 'left', 'left', 'center', 'left', 'center');
$table->width = '100%';
$table->data = array();

Expand All @@ -148,25 +150,33 @@
foreach ($tokens as $token) {
//TODO: retrieve context

$reset = "<a href=\"".$returnurl."&amp;action=reset&amp;tokenid=".$token->id."\">";
$reset .= get_string('reset')."</a>";
if ($token->creatorid == $USER->id) {
$reset = "<a href=\"".$returnurl."&amp;action=reset&amp;tokenid=".$token->id."\">";
$reset .= get_string('reset')."</a>";
$creator = $token->firstname." ".$token->lastname;
} else {
//retrive administrator name
require_once($CFG->dirroot.'/user/lib.php');
$creators = user_get_users_by_id(array($token->creatorid));
$admincreator = $creators[$token->creatorid];
$creator = $admincreator->firstname." ".$admincreator->lastname;
$reset = '';
}

$userprofilurl = new moodle_url('/user/view.php?id='.$token->creatorid);
$creatoratag = html_writer::start_tag('a', array('href' => $userprofilurl));
$creatoratag .= $creator;
$creatoratag .= html_writer::end_tag('a');

$validuntil = '';
if (!empty($token->validuntil)) {
$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);
$table->data[] = array($token->token, $token->name, $validuntil, $creatoratag, $reset);
}

$return .= $OUTPUT->table($table);
if (!empty($admintokeninfo)) {
$return .= $admintokeninfo;
}

} else {
$return .= get_string('notoken', 'webservice');
}
Expand Down

0 comments on commit b721742

Please sign in to comment.