Skip to content
Snippets Groups Projects
Unverified Commit 7e502d47 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Merge branch 'master' into Xnew-ui

parents 49d6f105 1e075699
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ the user logs in. ...@@ -42,7 +42,7 @@ the user logs in.
Example: Example:
90 => array( 90 => array(
'class' => 'class:Consent', 'class' => 'consent:Consent',
), ),
Using storage Using storage
......
...@@ -50,8 +50,7 @@ class Cookie extends \SimpleSAML\Module\consent\Store ...@@ -50,8 +50,7 @@ class Cookie extends \SimpleSAML\Module\consent\Store
if (!array_key_exists($cookieName, $_COOKIE)) { if (!array_key_exists($cookieName, $_COOKIE)) {
\SimpleSAML\Logger::debug( \SimpleSAML\Logger::debug(
'Consent cookie - no cookie with name \'' . 'Consent cookie - no cookie with name \''.$cookieName.'\'.'
$cookieName . '\'.'
); );
return false; return false;
} }
......
...@@ -15,6 +15,7 @@ assert($this->data['sppp'] === false || is_string($this->data['sppp'])); ...@@ -15,6 +15,7 @@ assert($this->data['sppp'] === false || is_string($this->data['sppp']));
// Parse parameters // Parse parameters
$dstName = $this->data['dstName']; $dstName = $this->data['dstName'];
$srcName = $this->data['srcName'];
$this->data['header'] = $this->t('{consent:consent:consent_header}'); $this->data['header'] = $this->t('{consent:consent:consent_header}');
$this->data['head'] = '<link rel="stylesheet" type="text/css" href="'. $this->data['head'] = '<link rel="stylesheet" type="text/css" href="'.
...@@ -25,7 +26,7 @@ $this->includeAtTemplateBase('includes/header.php'); ...@@ -25,7 +26,7 @@ $this->includeAtTemplateBase('includes/header.php');
<p><?php echo $this->data['consent_accept']; ?></p> <p><?php echo $this->data['consent_accept']; ?></p>
<?php <?php
if (isSet($this->data['consent_purpose'])) { if (isset($this->data['consent_purpose'])) {
echo '<p>'.$this->data['consent_purpose'].'</p>'; echo '<p>'.$this->data['consent_purpose'].'</p>';
} }
?> ?>
...@@ -58,108 +59,12 @@ if ($this->data['sppp'] !== false) { ...@@ -58,108 +59,12 @@ if ($this->data['sppp'] !== false) {
echo "</p>"; echo "</p>";
} }
/**
* Recursive attribute array listing function
*
* @param \SimpleSAML\XHTML\Template $t Template object
* @param array $attributes Attributes to be presented
* @param string $nameParent Name of parent element
*
* @return string HTML representation of the attributes
*/
function present_attributes($t, $attributes, $nameParent)
{
$translator = $t->getTranslator();
$alternate = array('odd', 'even');
$i = 0;
$summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"';
if (strlen($nameParent) > 0) {
$parentStr = strtolower($nameParent) . '_';
$str = '<table class="attributes" ' . $summary . '>';
} else {
$parentStr = '';
$str = '<table id="table_with_attributes" class="attributes" '. $summary .'>';
$str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') .
'</caption>';
}
foreach ($attributes as $name => $value) {
$nameraw = $name;
$name = $translator->getAttributeTranslation($parentStr . $nameraw);
if (preg_match('/^child_/', $nameraw)) {
// insert child table
$parentName = preg_replace('/^child_/', '', $nameraw);
foreach ($value as $child) {
$str .= "\n" . '<tr class="odd"><td style="padding: 2em">' .
present_attributes($t, $child, $parentName) . '</td></tr>';
}
} else {
// insert values directly
$str .= "\n" . '<tr class="' . $alternate[($i++ % 2)] .
'"><td><span class="attrname">' . htmlspecialchars($name) . '</span>';
$isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true);
if ($isHidden) {
$hiddenId = SimpleSAML\Utils\Random::generateID();
$str .= '<div class="attrvalue" style="display: none;" id="hidden_' . $hiddenId . '">';
} else {
$str .= '<div class="attrvalue">';
}
if (sizeof($value) > 1) {
// we hawe several values
$str .= '<ul>';
foreach ($value as $listitem) {
if ($nameraw === 'jpegPhoto') {
$str .= '<li><img src="data:image/jpeg;base64,' .
htmlspecialchars($listitem) .
'" alt="User photo" /></li>';
} else {
$str .= '<li>' . htmlspecialchars($listitem) . '</li>';
}
}
$str .= '</ul>';
} elseif (isset($value[0])) {
// we hawe only one value
if ($nameraw === 'jpegPhoto') {
$str .= '<img src="data:image/jpeg;base64,' .
htmlspecialchars($value[0]) .
'" alt="User photo" />';
} else {
$str .= htmlspecialchars($value[0]);
}
} // end of if multivalue
$str .= '</div>';
if ($isHidden) {
$str .= '<div class="attrvalue consent_showattribute" id="visible_' . $hiddenId . '">';
$str .= '... ';
$str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_' . $hiddenId;
$str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">';
$str .= $t->t('{consent:consent:show_attribute}');
$str .= '</a>';
$str .= '</div>';
}
$str .= '</td></tr>';
} // end else: not child table
} // end foreach
$str .= isset($attributes)? '</table>':'';
return $str;
}
echo '<h3 id="attributeheader">'. echo '<h3 id="attributeheader">'.
$this->t( $this->t(
'{consent:consent:consent_attributes_header}', '{consent:consent:consent_attributes_header}',
array('SPNAME' => $dstName, 'IDPNAME' => $srcName) array('SPNAME' => $dstName, 'IDPNAME' => $srcName)
) . ).'</h3>';
'</h3>';
echo present_attributes($this, $attributes, ''); echo $this->data['attributes_html'];
$this->includeAtTemplateBase('includes/footer.php'); $this->includeAtTemplateBase('includes/footer.php');
...@@ -68,8 +68,7 @@ if (array_key_exists('yes', $_REQUEST)) { ...@@ -68,8 +68,7 @@ if (array_key_exists('yes', $_REQUEST)) {
$attributeSet = $state['consent:store.attributeSet']; $attributeSet = $state['consent:store.attributeSet'];
\SimpleSAML\Logger::debug( \SimpleSAML\Logger::debug(
'Consent - saveConsent() : [' . $userId . '|' . 'Consent - saveConsent() : ['.$userId.'|'.$targetedId.'|'.$attributeSet.']'
$targetedId . '|' . $attributeSet . ']'
); );
try { try {
$store->saveConsent($userId, $targetedId, $attributeSet); $store->saveConsent($userId, $targetedId, $attributeSet);
...@@ -126,6 +125,38 @@ $t->data['noTarget'] = \SimpleSAML\Module::getModuleURL('consent/noconsent.php') ...@@ -126,6 +125,38 @@ $t->data['noTarget'] = \SimpleSAML\Module::getModuleURL('consent/noconsent.php')
$t->data['noData'] = array('StateId' => $id); $t->data['noData'] = array('StateId' => $id);
$t->data['attributes'] = $attributes; $t->data['attributes'] = $attributes;
$t->data['checked'] = $state['consent:checked']; $t->data['checked'] = $state['consent:checked'];
$t->data['stateId'] = $id;
$srcName = htmlspecialchars(is_array($srcName) ? $t->t($srcName) : $srcName);
$dstName = htmlspecialchars(is_array($dstName) ? $t->t($dstName) : $dstName);
$t->data['consent_attributes_header'] = $t->t(
'{consent:consent:consent_attributes_header}',
array('SPNAME' => $dstName, 'IDPNAME' => $srcName)
);
$t->data['consent_accept'] = $t->t(
'{consent:consent:consent_accept}',
array('SPNAME' => $dstName, 'IDPNAME' => $srcName)
);
if (array_key_exists('descr_purpose', $state['Destination'])) {
$t->data['consent_purpose'] = $t->t(
'{consent:consent:consent_purpose}',
array(
'SPNAME' => $dstName,
'SPDESC' => $translator->getPreferredTranslation(
\SimpleSAML\Utils\Arrays::arrayize(
$state['Destination']['descr_purpose'],
'en'
)
),
)
);
}
$t->data['srcName'] = $srcName;
$t->data['dstName'] = $dstName;
$srcName = htmlspecialchars(is_array($srcName) ? $translator->t($srcName) : $srcName); $srcName = htmlspecialchars(is_array($srcName) ? $translator->t($srcName) : $srcName);
$dstName = htmlspecialchars(is_array($dstName) ? $translator->t($dstName) : $dstName); $dstName = htmlspecialchars(is_array($dstName) ? $translator->t($dstName) : $dstName);
...@@ -216,7 +247,7 @@ function present_attributes($t, $attributes, $nameParent) ...@@ -216,7 +247,7 @@ function present_attributes($t, $attributes, $nameParent)
$alternate = array('odd', 'even'); $alternate = array('odd', 'even');
$i = 0; $i = 0;
$summary = 'summary="' . $translator->t('{consent:consent:table_summary}') . '"'; $summary = 'summary="'.$t->t('{consent:consent:table_summary}').'"';
if (strlen($nameParent) > 0) { if (strlen($nameParent) > 0) {
$parentStr = strtolower($nameParent).'_'; $parentStr = strtolower($nameParent).'_';
...@@ -224,8 +255,7 @@ function present_attributes($t, $attributes, $nameParent) ...@@ -224,8 +255,7 @@ function present_attributes($t, $attributes, $nameParent)
} else { } else {
$parentStr = ''; $parentStr = '';
$str = '<table id="table_with_attributes" class="attributes" '.$summary.'>'; $str = '<table id="table_with_attributes" class="attributes" '.$summary.'>';
$str .= "\n" . '<caption>' . $translator->t('{consent:consent:table_caption}') . $str .= "\n".'<caption>'.$t->t('{consent:consent:table_caption}').'</caption>';
'</caption>';
} }
foreach ($attributes as $name => $value) { foreach ($attributes as $name => $value) {
...@@ -248,7 +278,6 @@ function present_attributes($t, $attributes, $nameParent) ...@@ -248,7 +278,6 @@ function present_attributes($t, $attributes, $nameParent)
$isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true); $isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true);
if ($isHidden) { if ($isHidden) {
$hiddenId = \SimpleSAML\Utils\Random::generateID(); $hiddenId = \SimpleSAML\Utils\Random::generateID();
$str .= '<div class="attrvalue hidden" id="hidden_'.$hiddenId.'">'; $str .= '<div class="attrvalue hidden" id="hidden_'.$hiddenId.'">';
} else { } else {
$str .= '<div class="attrvalue">'; $str .= '<div class="attrvalue">';
...@@ -260,8 +289,7 @@ function present_attributes($t, $attributes, $nameParent) ...@@ -260,8 +289,7 @@ function present_attributes($t, $attributes, $nameParent)
foreach ($value as $listitem) { foreach ($value as $listitem) {
if ($nameraw === 'jpegPhoto') { if ($nameraw === 'jpegPhoto') {
$str .= '<li><img src="data:image/jpeg;base64,'. $str .= '<li><img src="data:image/jpeg;base64,'.
htmlspecialchars($listitem) . htmlspecialchars($listitem).'" alt="User photo" /></li>';
'" alt="User photo" /></li>';
} else { } else {
$str .= '<li>'.htmlspecialchars($listitem).'</li>'; $str .= '<li>'.htmlspecialchars($listitem).'</li>';
} }
...@@ -271,8 +299,7 @@ function present_attributes($t, $attributes, $nameParent) ...@@ -271,8 +299,7 @@ function present_attributes($t, $attributes, $nameParent)
// we hawe only one value // we hawe only one value
if ($nameraw === 'jpegPhoto') { if ($nameraw === 'jpegPhoto') {
$str .= '<img src="data:image/jpeg;base64,'. $str .= '<img src="data:image/jpeg;base64,'.
htmlspecialchars($value[0]) . htmlspecialchars($value[0]).'" alt="User photo" />';
'" alt="User photo" />';
} else { } else {
$str .= htmlspecialchars($value[0]); $str .= htmlspecialchars($value[0]);
} }
...@@ -284,7 +311,7 @@ function present_attributes($t, $attributes, $nameParent) ...@@ -284,7 +311,7 @@ function present_attributes($t, $attributes, $nameParent)
$str .= '... '; $str .= '... ';
$str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_'.$hiddenId; $str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_'.$hiddenId;
$str .= '\'); SimpleSAML_hide(\'visible_'.$hiddenId.'\');">'; $str .= '\'); SimpleSAML_hide(\'visible_'.$hiddenId.'\');">';
$str .= $translator->t('{consent:consent:show_attribute}'); $str .= $t->t('{consent:consent:show_attribute}');
$str .= '</a>'; $str .= '</a>';
$str .= '</div>'; $str .= '</div>';
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment