MDL-76722 user: Add new update_user_device_public_key webservice

This commit is contained in:
Alex Morris 2023-03-01 11:24:57 +13:00 committed by Andrew Nicols
parent 7c843b380b
commit 9bc236d48d
7 changed files with 381 additions and 0 deletions

View file

@ -1363,3 +1363,28 @@ function user_edit_map_field_purpose($userid, $fieldname) {
return $purpose;
}
/**
* Update the users public key for the specified device and app.
*
* @param string $uuid The device UUID.
* @param string $appid The app id, usually something like com.moodle.moodlemobile.
* @param string $publickey The app generated public key.
* @return bool
* @since Moodle 4.2
*/
function user_update_device_public_key(string $uuid, string $appid, string $publickey): bool {
global $USER, $DB;
if (!$DB->get_record('user_devices',
['uuid' => $uuid, 'appid' => $appid, 'userid' => $USER->id]
)) {
return false;
}
$DB->set_field('user_devices', 'publickey', $publickey,
['uuid' => $uuid, 'appid' => $appid, 'userid' => $USER->id]
);
return true;
}