MDL-65959 badge: Enable OB2.1 *connection* with cross domain ability

This commit is contained in:
Peter Dias
2020-10-26 18:36:26 +08:00
parent b0007a154c
commit b0e1edd427
5 changed files with 53 additions and 28 deletions
+6 -10
View File
@@ -103,16 +103,6 @@ if ($backpack) {
$bp->set_backpack_collections($backpack->id, $groups);
redirect(new moodle_url('/badges/mybadges.php'));
}
} else if (badges_open_badges_backpack_api() == OPEN_BADGES_V2P1) {
// If backpack is version 2.1 to redirect on the backpack site to login.
// User input username/email/password on the backpack site
// After confirm the scopes.
$form = new \core_badges\form\backpack(new moodle_url('/badges/mybackpack.php'));
if ($form->is_cancelled()) {
redirect(new moodle_url('/badges/mybadges.php'));
} else if ($data = $form->get_submitted_data()) {
redirect(new moodle_url('/badges/backpack-connect.php'));
}
} else {
// If backpack is not connected, need to connect first.
// To create a new connection to the backpack, first we need to verify the user's email address:
@@ -130,8 +120,14 @@ if ($backpack) {
$params['backpackid'] = get_user_preferences('badges_email_verify_backpackid');
$form = new \core_badges\form\backpack(new moodle_url('/badges/mybackpack.php'), $params);
$data = $form->get_submitted_data();
if ($form->is_cancelled()) {
redirect(new moodle_url('/badges/mybadges.php'));
} else if (badges_open_badges_backpack_api($data->externalbackpackid) == OPEN_BADGES_V2P1) {
// If backpack is version 2.1 to redirect on the backpack site to login.
// User input username/email/password on the backpack site
// After confirm the scopes.
redirect(new moodle_url('/badges/backpack-connect.php', ['backpackid' => $data->externalbackpackid]));
} else if ($data = $form->get_data()) {
// The form may have been submitted under one of the following circumstances:
// 1. After clicking 'Connect to backpack'. We'll have $data->email.