Commit da422c57 authored by David Venhoek's avatar David Venhoek
Browse files

Updated logic to work with pbdf infra and support multiple age ranges.

parent 1dc1ad6f
<?php
define('IRMA_SERVER_URL', 'http://localhost:8088');
define('API_TOKEN', '');
......@@ -135,7 +135,7 @@
Leeftijd 18+
</div>
</div>
<button class="add-to-cart-btn" id="product01"> Bewijs leeftijd en
<button class="add-to-cart-btn" id="product01" data-minage=18> Bewijs leeftijd en
bestel</button>
</div>
</div>
......@@ -161,7 +161,7 @@
Leeftijd 16+
</div>
</div>
<button class="add-to-cart-btn" id="product02"> Bewijs leeftijd en
<button class="add-to-cart-btn" id="product02" data-minage=16> Bewijs leeftijd en
bestel</button>
</div>
</div>
......@@ -187,7 +187,7 @@
Leeftijd 12+
</div>
</div>
<button class="add-to-cart-btn" id="product03"> Bewijs leeftijd en
<button class="add-to-cart-btn" id="product03" data-minage=12> Bewijs leeftijd en
bestel</button>
</div>
</div>
......@@ -213,7 +213,7 @@
Leeftijd 18+
</div>
</div>
<button class="add-to-cart-btn" id="product04"> Bewijs leeftijd en
<button class="add-to-cart-btn" id="product04" data-minage=18> Bewijs leeftijd en
bestel</button>
</div>
</div>
......
......@@ -86,7 +86,7 @@
$('.add-to-cart-btn').on('click', function (element) {
$('#snackbar').removeClass('show');
console.log("Age verification started");
$.get('https://privacybydesign.foundation/demo/start_session.php?type=18plus&lang=nl', function (sessionpackagejson) {
$.get('/start_session.php?type='+element.currentTarget.attr('data-minage')+'plus', function (sessionpackagejson) {
let sessionpackage = JSON.parse(sessionpackagejson);
let options = {
server: sessionpackage.sessionPtr.u.split('/irma')[0],
......
<?php
require_once 'config.php';
date_default_timezone_set('UTC');
$protocol = explode(':', IRMA_SERVER_URL, 2)[0];
$sprequests = [
'18plus' => [
'@context' => 'https://irma.app/ld/request/disclosure/v2',
'disclose' => [
[
['pbdf.pbdf.ageLimits.over18'],
['pbdf.nijmegen.ageLimits.over18'],
['pbdf.gemeente.personalData.over18'],
],
],
],
'16plus' => [
'@context' => 'https://irma.app/ld/request/disclosure/v2',
'disclose' => [
[
['pbdf.pbdf.ageLimits.over16'],
['pbdf.nijmegen.ageLimits.over16'],
['pbdf.gemeente.personalData.over16'],
],
],
],
'12plus' => [
'@context' => 'https://irma.app/ld/request/disclosure/v2',
'disclose' => [
[
['pbdf.pbdf.ageLimits.over12'],
['pbdf.nijmegen.ageLimits.over12'],
['pbdf.gemeente.personalData.over12'],
],
],
],
];
function start_session($type) {
global $sprequests, $protocol;
if (array_key_exists($type, $sprequests))
$sessionrequest = $sprequests[$type];
else
stop();
$jsonsr = json_encode($sessionrequest);
$api_call = array(
$protocol => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n"
. "Content-Length: " . strlen($jsonsr) . "\r\n"
. "Authorization: " . API_TOKEN . "\r\n",
'content' => $jsonsr
)
);
$resp = file_get_contents(IRMA_SERVER_URL . '/session', false, stream_context_create($api_call));
if (! $resp) {
error();
}
return $resp;
}
function error() {
http_response_code(500);
echo 'Internal server error';
exit();
}
function stop() {
http_response_code(400);
echo 'Invalid request';
exit();
}
if (!isset($_GET['type']))
stop();
echo start_session($_GET['type']);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment