Merge branch 'MDL-78102-402' of https://github.com/sarjona/moodle into MOODLE_402_STABLE
This commit is contained in:
@@ -50,7 +50,7 @@ if (!is_null($storedsecret)) {
|
||||
// Make sure we have all the required information before trying to save the connection.
|
||||
$backpackuid = $bp->authenticate();
|
||||
if (empty($backpackuid) || !empty($backpackuid->error)) {
|
||||
redirect(new moodle_url($redirect), get_string('backpackconnectionunexpectedresult', 'badges'),
|
||||
redirect(new moodle_url($redirect), get_string('backpackconnectionunexpectedresult', 'badges', $backpackuid->error),
|
||||
null, \core\output\notification::NOTIFY_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -125,29 +125,38 @@ class backpack extends external_backpack {
|
||||
* Validates form data
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
global $CFG;
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
if (badges_open_badges_backpack_api() == OPEN_BADGES_V2P1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// We don't need to verify the email address if we're clearing a pending email verification attempt.
|
||||
if (isset($data['revertbutton'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
// Email and password can't be blank.
|
||||
if (empty($data['backpackemail'])) {
|
||||
$errors['backpackemail'] = get_string('backpackemail_required', 'badges');
|
||||
}
|
||||
if (empty($data['password'])) {
|
||||
$errors['password'] = get_string('password_required', 'badges');
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
return $errors;
|
||||
}
|
||||
// We don't need to verify the email address if we're clearing a pending email verification attempt.
|
||||
if (!isset($data['revertbutton'])) {
|
||||
$check = new stdClass();
|
||||
$check->email = $data['backpackemail'];
|
||||
$check->password = $data['password'];
|
||||
$sitebackpack = badges_get_site_backpack($data['externalbackpackid']);
|
||||
$bp = new \core_badges\backpack_api($sitebackpack, $check);
|
||||
|
||||
$result = $bp->authenticate();
|
||||
if ($result === false || !empty($result->error)) {
|
||||
$errors['backpackemail'] = get_string('backpackconnectionunexpectedresult', 'badges');
|
||||
$msg = $bp->get_authentication_error();
|
||||
if (!empty($msg)) {
|
||||
$errors['backpackemail'] .= '<br/><br/>';
|
||||
$errors['backpackemail'] .= get_string('backpackconnectionunexpectedmessage', 'badges', $msg);
|
||||
}
|
||||
}
|
||||
// Check the given credentials (email and password) are valid for this backpack.
|
||||
$check = new stdClass();
|
||||
$check->email = $data['backpackemail'];
|
||||
$check->password = $data['password'];
|
||||
$sitebackpack = badges_get_site_backpack($data['externalbackpackid']);
|
||||
$bp = new \core_badges\backpack_api($sitebackpack, $check);
|
||||
|
||||
$result = $bp->authenticate();
|
||||
if ($result === false || !empty($result->error)) {
|
||||
$msg = $bp->get_authentication_error();
|
||||
$errors['backpackemail'] = get_string('backpackconnectionunexpectedresult', 'badges', $msg);
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ if ($backpack) {
|
||||
badges_disconnect_user_backpack($USER->id);
|
||||
redirect(new moodle_url('/badges/mybackpack.php'));
|
||||
} else if (isset($data->backpackemail)) {
|
||||
// There are no errors, so the verification email can be sent.
|
||||
if (badges_send_verification_email($data->backpackemail, $data->externalbackpackid, $data->password)) {
|
||||
$a = get_user_preferences('badges_email_verify_backpackid');
|
||||
redirect(new moodle_url('/badges/mybackpack.php'),
|
||||
|
||||
@@ -181,3 +181,18 @@ Feature: Backpack badges
|
||||
And I set the field "externalbackpackid" to "https://test.com/"
|
||||
And I should see "Email address"
|
||||
And I should see "Password"
|
||||
|
||||
@javascript
|
||||
Scenario: Check backpack form validation as a student
|
||||
Given I log in as "student1"
|
||||
And I follow "Preferences" in the user menu
|
||||
And I follow "Backpack settings"
|
||||
And I set the field "externalbackpackid" to "https://test.com/"
|
||||
And I set the field "password" to ""
|
||||
When I click on "Connect to backpack" "button"
|
||||
Then I should see "Password can't be blank"
|
||||
And I should not see "Email address can't be blank"
|
||||
And I set the field "backpackemail" to ""
|
||||
And I click on "Connect to backpack" "button"
|
||||
And I should see "Email address can't be blank"
|
||||
And I should see "Password can't be blank"
|
||||
|
||||
+3
-1
@@ -105,11 +105,12 @@ $string['backpackconnection_help'] = 'Connecting to a backpack enables you to sh
|
||||
$string['backpackconnectioncancelattempt'] = 'Connect using a different email address';
|
||||
$string['backpackconnectionconnect'] = 'Connect to backpack';
|
||||
$string['backpackconnectionresendemail'] = 'Resend verification email';
|
||||
$string['backpackconnectionunexpectedresult'] = 'There was a problem connecting to your backpack. Please check the credentials and try again.';
|
||||
$string['backpackconnectionunexpectedresult'] = 'There was a problem connecting to your backpack. Your backpack provider is sending this message: \'{$a}\'.';
|
||||
$string['backpackconnectionunexpectedmessage'] = 'The backpack returned the error: "{$a}".';
|
||||
$string['backpackdetails'] = 'Backpack settings';
|
||||
$string['backpackdisconnected'] = 'Backpack is disconnected';
|
||||
$string['backpackemail'] = 'Email address';
|
||||
$string['backpackemail_required'] = 'Email address can\'t be blank';
|
||||
$string['backpackemail_help'] = 'The email address associated with your backpack. While you are connected, any badges earned on this site will be associated with this email address.';
|
||||
$string['backpackemailverificationpending'] = 'Verification pending';
|
||||
$string['backpackemailverifyemailbody'] = 'Hi,
|
||||
@@ -458,6 +459,7 @@ $string['openbadgesv1'] = 'Open Badges v1.0';
|
||||
$string['openbadgesv2'] = 'Open Badges v2.0';
|
||||
$string['openbadgesv2p1'] = 'Open Badges v2.1';
|
||||
$string['othernavigation'] = 'Other navigation ...';
|
||||
$string['password_required'] = 'Password can\'t be blank';
|
||||
$string['potentialrecipients'] = 'Potential badge recipients';
|
||||
$string['preferences'] = 'Badge preferences';
|
||||
$string['privacy:metadata:backpack'] = 'A record of user\'s backpacks';
|
||||
|
||||
Reference in New Issue
Block a user