MDL-78637 webservice: display token info after user performs reset.

This commit is contained in:
Paul Holden 2023-07-03 14:25:17 +01:00
parent 8dbb6183ff
commit 686b054b78
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
2 changed files with 29 additions and 1 deletions

View File

@ -57,6 +57,15 @@ if ( !is_siteadmin($USER->id)
// Delete the token that need to be regenerated.
require_sesskey();
$webservice->delete_user_ws_token($tokenid);
// Now re-create one against the same service.
\core_external\util::generate_token(
EXTERNAL_TOKEN_PERMANENT,
\core_external\util::get_service_by_id($token->externalserviceid),
$USER->id,
context_system::instance()
);
redirect($PAGE->url, get_string('resettokencomplete', 'core_webservice'));
}
}
@ -108,6 +117,23 @@ echo $OUTPUT->header();
if (!empty($resetconfirmation)) {
echo $resetconfirmation;
} else {
if (!empty($SESSION->webservicenewlycreatedtoken)) {
$webservicemanager = new webservice();
$newtoken = $webservicemanager->get_created_by_user_ws_token(
$USER->id,
$SESSION->webservicenewlycreatedtoken
);
if ($newtoken) {
// Unset the session variable.
unset($SESSION->webservicenewlycreatedtoken);
// Display the newly created token.
echo $OUTPUT->render_from_template(
'core_admin/webservice_token_new', ['token' => $newtoken->token, 'tokenname' => $newtoken->tokenname]
);
}
}
echo $webservicetokenboxhtml;
echo $rsstokenboxhtml;
}

View File

@ -413,8 +413,10 @@ class webservice {
* The returned value is a stdClass:
* ->id token id
* ->token
* ->tokenname
* ->firstname user firstname
* ->lastname
* ->externalserviceid
* ->name service name
*
* @param int $userid user id
@ -424,7 +426,7 @@ class webservice {
public function get_created_by_user_ws_token($userid, $tokenid) {
global $DB;
$sql = "SELECT
t.id, t.token, t.name AS tokenname, u.firstname, u.lastname, s.name
t.id, t.token, t.name AS tokenname, u.firstname, u.lastname, t.externalserviceid, s.name
FROM
{external_tokens} t, {user} u, {external_services} s
WHERE