Skip to content

Commit

Permalink
MDL-65959 badges: Do not use badge user preference after verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dias committed Oct 26, 2020
1 parent 3cae942 commit 96ec45c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion badges/backpack-add.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$badge = new badge($badgeid);
$backpack = $DB->get_record('badge_backpack', array('userid' => $USER->id));
$sitebackpack = badges_get_site_primary_backpack();
$userbackpack = badges_get_site_backpack($backpack->externalbackpackid);
$userbackpack = badges_get_site_backpack($backpack->externalbackpackid, $USER->id);
$assertion = new core_badges_assertion($id, $sitebackpack->apiversion);
$api = new \core_badges\backpack_api($sitebackpack);
$api->authenticate();
Expand Down
2 changes: 2 additions & 0 deletions badges/backpackemailverify.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
// Remove the verification vars and redirect to the mypackpack page.
unset_user_preference('badges_email_verify_secret');
unset_user_preference('badges_email_verify_address');
unset_user_preference('badges_email_verify_backpackid');
unset_user_preference('badges_email_verify_password');
redirect(new moodle_url($redirect), get_string('backpackemailverifysuccess', 'badges'),
null, \core\output\notification::NOTIFY_SUCCESS);
} else {
Expand Down
16 changes: 7 additions & 9 deletions lib/badgeslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,20 +922,21 @@ function badges_open_badges_backpack_api() {
}

/**
* Get a site backpacks by id or url.
* Get a site backpacks by id for a particular user or site (if userid is 0)
*
* @param int $id The backpack id.
* @param int $userid The owner of the backpack, 0 if it's a sitewide backpack else a user's site backpack
* @return array(stdClass)
*/
function badges_get_site_backpack($id) {
function badges_get_site_backpack($id, int $userid = 0) {
global $DB;

$sql = "SELECT beb.*, bb.id AS badgebackpack, bb.password, bb.email AS backpackemail
FROM {badge_external_backpack} beb
LEFT JOIN {badge_backpack} bb ON bb.externalbackpackid = beb.id AND bb.userid=:userid
WHERE beb.id=:id";

return $DB->get_record_sql($sql, ['id' => $id, 'userid' => 0]);
return $DB->get_record_sql($sql, ['id' => $id, 'userid' => $userid]);
}

/**
Expand All @@ -957,11 +958,7 @@ function badges_get_site_primary_backpack() {
function badges_get_site_backpacks() {
global $DB, $CFG;

$sql = "SELECT beb.*, bb.id as badgebackpack, bb.password, bb.email as backpackemail
FROM {badge_external_backpack} beb
LEFT JOIN {badge_backpack} bb ON bb.externalbackpackid = beb.id
WHERE bb.id IS NULL OR bb.userid=:userid";
$all = $DB->get_records_sql($sql, ['userid' => 0]);
$all = $DB->get_records('badge_external_backpack');

foreach ($all as $key => $bp) {
if ($bp->id == $CFG->badges_site_backpack) {
Expand Down Expand Up @@ -994,14 +991,15 @@ function badges_get_badge_api_versions() {
function badges_get_default_issuer() {
global $CFG, $SITE;

$sitebackpack = badges_get_site_primary_backpack();
$issuer = array();
$issuerurl = new moodle_url('/');
$issuer['name'] = $CFG->badges_defaultissuername;
if (empty($issuer['name'])) {
$issuer['name'] = $SITE->fullname ? $SITE->fullname : $SITE->shortname;
}
$issuer['url'] = $issuerurl->out(false);
$issuer['email'] = $CFG->badges_defaultissuercontact;
$issuer['email'] = $sitebackpack->backpackemail ?? $CFG->badges_defaultissuercontact;
$issuer['@context'] = OPEN_BADGES_V2_CONTEXT;
$issuerid = new moodle_url('/badges/issuer_json.php');
$issuer['id'] = $issuerid->out(false);
Expand Down

0 comments on commit 96ec45c

Please sign in to comment.