From 3c57ce6e72700ac4772dfb8acee2559e204831cd Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Thu, 23 Mar 2017 11:08:56 +0800 Subject: [PATCH] MDL-57429 badges: handle curl problems nicely during connection creation - Properly validate the displayer API response before sending the verification email. - Properly validate the displayer API response before creating the saved connection. --- badges/backpack_form.php | 2 ++ badges/backpackemailverify.php | 11 ++++++++++- lang/en/badges.php | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/badges/backpack_form.php b/badges/backpack_form.php index dda5ed4774e..417c96051ba 100644 --- a/badges/backpack_form.php +++ b/badges/backpack_form.php @@ -101,6 +101,8 @@ class edit_backpack_form extends moodleform { $request = $bp->curl_request('user'); if (isset($request->status) && $request->status == 'missing') { $errors['email'] = get_string('error:nosuchuser', 'badges'); + } else if (!isset($request->status) || $request->status !== 'okay') { + $errors['email'] = get_string('backpackconnectionunexpectedresult', 'badges'); } } return $errors; diff --git a/badges/backpackemailverify.php b/badges/backpackemailverify.php index 2ffb35fe315..d9dfda25309 100644 --- a/badges/backpackemailverify.php +++ b/badges/backpackemailverify.php @@ -43,11 +43,20 @@ if (!is_null($storedsecret)) { $data->email = $storedemail; $bp = new OpenBadgesBackpackHandler($data); + // Make sure we have all the required information before trying to save the connection. + $backpackuser = $bp->curl_request('user'); + if (isset($backpackuser->status) && $backpackuser->status === 'okay' && isset($backpackuser->userId)) { + $backpackuid = $backpackuser->userId; + } else { + redirect(new moodle_url($redirect), get_string('backpackconnectionunexpectedresult', 'badges'), + null, \core\output\notification::NOTIFY_ERROR); + } + $obj = new stdClass(); $obj->userid = $USER->id; $obj->email = $data->email; $obj->backpackurl = $data->backpackurl; - $obj->backpackuid = $bp->curl_request('user')->userId; + $obj->backpackuid = $backpackuid; $obj->autosync = 0; $obj->password = ''; $DB->insert_record('badge_backpack', $obj); diff --git a/lang/en/badges.php b/lang/en/badges.php index 7e9cda52ac9..d89311757fd 100644 --- a/lang/en/badges.php +++ b/lang/en/badges.php @@ -94,6 +94,7 @@ For more information about Persona visit