Skip to content
Snippets Groups Projects
Commit a4fbef75 authored by Dominik Baránek's avatar Dominik Baránek
Browse files

fix: Do not remember same idp twice

parent 6b5f7cd1
No related branches found
No related tags found
1 merge request!14fix: Do not remember same idp twice
......@@ -217,6 +217,17 @@ class Campusidp extends Source
}
}
public static function isIdpInCookie($idps, $entityid)
{
foreach ($idps as $idp) {
if ($idp['entityid'] === $entityid) {
return true;
}
}
return false;
}
public function logout(&$state)
{
assert(is_array($state));
......
......@@ -47,21 +47,27 @@ if (array_key_exists('source', $_POST)) {
!empty($wayfConfig['components'][$_POST['componentIndex']]) &&
$wayfConfig['components'][$_POST['componentIndex']]['name'] === 'searchbox')
{
$chosenIdp = [];
$chosenIdp['entityid'] = $_POST['searchbox'];
$chosenIdp['name'] = $metadata[$_POST['searchbox']]['name'];
$chosenIdp['img'] = $wayfConfig['components'][$_POST['componentIndex']]['logos'][$_POST['searchbox']]
?? Campusidp::getMostSquareLikeImg($metadata[$_POST['searchbox']]);
$chosenIdp['index'] = $_POST['componentIndex'];
$prevIdps = Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS) === null ? [] : json_decode(gzinflate(base64_decode(Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS))));
$prevIdps[] = $chosenIdp;
while (strlen(base64_encode(gzdeflate(json_encode($prevIdps)))) > 4093) {
array_shift($prevIdps);
}
$prevIdps = Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS) === null ?
[] :
json_decode(gzinflate(base64_decode(Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS))), true);
if (!Campusidp::isIdpInCookie($prevIdps, $_POST['searchbox'])) {
$chosenIdp = [];
$chosenIdp['entityid'] = $_POST['searchbox'];
$chosenIdp['name'] = $metadata[$_POST['searchbox']]['name'];
$chosenIdp['img'] = $wayfConfig['components'][$_POST['componentIndex']]['logos'][$_POST['searchbox']]
?? Campusidp::getMostSquareLikeImg($metadata[$_POST['searchbox']]);
$chosenIdp['index'] = $_POST['componentIndex'];
Campusidp::setCookie(Campusidp::COOKIE_PREVIOUS_IDPS, base64_encode(gzdeflate(json_encode($prevIdps))));
$prevIdps[] = $chosenIdp;
while (strlen(base64_encode(gzdeflate(json_encode($prevIdps)))) > 4093) {
array_shift($prevIdps);
}
Campusidp::setCookie(Campusidp::COOKIE_PREVIOUS_IDPS, base64_encode(gzdeflate(json_encode($prevIdps))));
}
}
Campusidp::delegateAuthentication($_POST['source'], $state);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment