Exemplo n.º 1
0
 /**
  * Validates form data
  */
 public function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $check = new stdClass();
     $check->backpackurl = $data['backpackurl'];
     $check->email = $data['email'];
     $bp = new OpenBadgesBackpackHandler($check);
     $request = $bp->curl_request('user');
     if (isset($request->status) && $request->status == 'missing') {
         $errors['email'] = get_string('error:nosuchuser', 'badges');
     }
     return $errors;
 }
Exemplo n.º 2
0
    } else {
        $reason = get_string('error:requesterror', 'badges', $curl->errno);
    }
    badges_send_response('failure', $reason);
}
$data = json_decode($result);
if (!isset($data->status) || $data->status != 'okay') {
    $reason = isset($data->reason) ? $data->reason : get_string('error:connectionunknownreason', 'badges');
    badges_send_response('failure', $reason);
}
// Make sure email matches a backpack.
$check = new stdClass();
$check->backpackurl = BADGE_BACKPACKURL;
$check->email = $data->email;
$bp = new OpenBadgesBackpackHandler($check);
$request = $bp->curl_request('user');
if (isset($request->status) && $request->status == 'missing') {
    $reason = get_string('error:backpackemailnotfound', 'badges', $data->email);
    badges_send_response('failure', $reason);
} else {
    if (empty($request->userId)) {
        $reason = get_string('error:backpackdatainvalid', 'badges');
        badges_send_response('failure', $reason);
    } else {
        $backpackuid = $request->userId;
    }
}
// Insert record.
$obj = new stdClass();
$obj->userid = $USER->id;
$obj->email = $data->email;
Exemplo n.º 3
0
                $obj->collectionid = (int) $group;
                if (!$DB->record_exists('badge_external', array('backpackid' => $obj->backpackid, 'collectionid' => $obj->collectionid))) {
                    $DB->insert_record('badge_external', $obj);
                }
            }
            redirect(new moodle_url('/badges/mybadges.php'));
        }
    }
} else {
    // If backpack is not connected, need to connect first.
    $form = new edit_backpack_form();
    if ($form->is_cancelled()) {
        redirect(new moodle_url('/badges/mybadges.php'));
    } else {
        if ($data = $form->get_data()) {
            $bp = new OpenBadgesBackpackHandler($data);
            $obj = new stdClass();
            $obj->userid = $data->userid;
            $obj->email = $data->email;
            $obj->backpackurl = $data->backpackurl;
            $obj->backpackuid = $bp->curl_request('user')->userId;
            $obj->autosync = 0;
            $obj->password = '';
            $DB->insert_record('badge_backpack', $obj);
            redirect(new moodle_url('/badges/mybackpack.php'));
        }
    }
}
echo $OUTPUT->header();
$form->display();
echo $OUTPUT->footer();