Skip to content

Commit

Permalink
Reorganise backpack_api and backpack_api_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jan 10, 2025
1 parent f4f1666 commit 016613a
Show file tree
Hide file tree
Showing 12 changed files with 1,556 additions and 46 deletions.
6 changes: 4 additions & 2 deletions badges/backpack-add.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use core_badges\backpackapi_base;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -62,7 +64,7 @@
$badgeadded = false;
if (badges_open_badges_backpack_api() == OPEN_BADGES_V2) {
$sitebackpack = badges_get_site_primary_backpack();
$api = new \core_badges\backpack_api($sitebackpack);
$api = backpackapi_base::create_from_externalbackpack($userbackpack);
$response = $api->authenticate();

// A numeric response indicates a valid successful authentication. Else an error object will be returned.
Expand Down Expand Up @@ -137,7 +139,7 @@
// based on email address.
// - This is only needed when the backpacks are from different regions.
if ($assertionentityid && !badges_external_get_mapping($userbackpack->id, OPEN_BADGES_V2_TYPE_ASSERTION, $assertionid)) {
$userapi = new \core_badges\backpack_api($userbackpack, $backpack);
$userapi = backpackapi_base::create_from_externalbackpack($userbackpack);
$userapi->authenticate();
$response = $userapi->import_badge_assertion($assertionentityid);
if (!$response) {
Expand Down
6 changes: 4 additions & 2 deletions badges/backpack-export.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use core_badges\backpackapi_base;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -52,12 +54,12 @@

$redirecturl = new moodle_url('/badges/mybadges.php');
if ($hash) {
$api = new core_badges\backpack_api2p1($backpack);
$api = backpackapi_base::create_from_externalbackpack($backpack);
$notify = $api->put_assertions($hash);
if (!empty($notify['status']) && $notify['status'] == \core\output\notification::NOTIFY_SUCCESS) {
redirect($redirecturl, $notify['message'], null, \core\output\notification::NOTIFY_SUCCESS);
} else if (!empty($notify['status']) && $notify['status'] == \core\output\notification::NOTIFY_ERROR) {
redirect($redirecturl, $notify['message'], null, \core\output\notification::NOTIFY_ERROR);
}
}
redirect($redirecturl);
redirect($redirecturl);
13 changes: 6 additions & 7 deletions badges/backpackemailverify.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use core_badges\backpackapi_base;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -40,12 +42,9 @@
$password = get_user_preferences('badges_email_verify_password');

$backpack = badges_get_site_backpack($backpackid);

$data = new stdClass();
$data->email = $storedemail;
$data->password = $password;
$data->externalbackpackid = $backpackid;
$bp = new \core_badges\backpack_api($backpack, $data);
$backpack->email = $storedemail;
$backpack->password = $password;
$bp = backpackapi_base::create_from_externalbackpack($backpack);

// Make sure we have all the required information before trying to save the connection.
$backpackuid = $bp->authenticate();
Expand All @@ -56,7 +55,7 @@

$values = [
'userid' => $USER->id,
'backpackemail' => $data->email,
'backpackemail' => $storedemail,
'externalbackpackid' => $backpackid,
'backpackuid' => $backpackuid,
'autosync' => 0,
Expand Down
Loading

0 comments on commit 016613a

Please sign in to comment.