Add admin button to user menu, if admin

This commit is contained in:
Yorin Anne De Jong 2018-02-13 18:30:49 +01:00
parent edde8b6927
commit 24b6af1799
5 changed files with 17 additions and 6 deletions

View File

@ -25,7 +25,8 @@ function navbar($depth, $active = NULL) {
return $result . "\t</ul>\n";
}
function loginBar($sp = 'default-sp') {
function loginBar($sp = null, $pdo = null) {
if (is_null($sp)) $sp = 'default-sp';
$result = "\n";
require_once(__DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple($sp);
@ -44,10 +45,19 @@ function loginBar($sp = 'default-sp') {
$attr = $as->getAttributes();
if($attr) {
$uname = $attr['uid'][0];
if (isset($pdo)) {
$userManager = new \pvv\admin\UserManager($pdo);
$isAdmin = $userManager->isAdmin($uname);
} else {
$isAdmin = false;
}
$result .= "\t<a id=\"login\" href=\"#usermenu\" aria-hidden=\"true\">${svgWhite}" . htmlspecialchars($uname) . "</a>\n";
$result .= "\n\t<ul id=\"usermenu\">\n";
$result .= "\n\t\t<li><a id=\"login\" href=\"#\">${svgBlue}" . htmlspecialchars($uname) . "</a></li>\n";
if ($isAdmin) {
$result .= "\n\t\t<li><a href=\"/admin/\">Admin</a></li>\n";
}
$result .= "\n\t\t<li><a href=\"" . htmlspecialchars($as->getLogoutURL()) . "\">Logg ut</a></li>\n";
$result .= "\n\t</ul>\n";
} else {

View File

@ -18,7 +18,8 @@ $projectGroup = $userManager->hasGroup($uname, 'prosjekt');
$activityGroup = $userManager->hasGroup($uname, 'aktiviteter');
if(!($isAdmin | $projectGroup | $activityGroup)){
echo 'Her har du ikke lov\'t\'å\'værra!!!';
header('Content-Type: text/plain', true, 403);
echo "Her har du ikke lov't'å'værra!!!\r\n";
exit();
}
?>
@ -54,5 +55,5 @@ if(!($isAdmin | $projectGroup | $activityGroup)){
<nav>
<?= navbar(1); ?>
<?= loginbar(); ?>
<?= loginbar(null, $pdo); ?>
</nav>

View File

@ -80,5 +80,5 @@ foreach($events as $event) {
<nav>
<?= navbar(1, 'aktiviteter'); ?>
<?= loginbar(); ?>
<?= loginbar(null, $pdo); ?>
</nav>

View File

@ -39,5 +39,5 @@ Det er også mulig å ta i bruk analog kontakt ved å møte opp <a href="https:/
<nav>
<?= navbar(1, 'kontakt'); ?>
<?= loginbar(); ?>
<?= loginbar(null, $pdo); ?>
</nav>

View File

@ -69,5 +69,5 @@ $projects = $projectManager->getAll();
<nav>
<?= navbar(1, 'prosjekt'); ?>
<?= loginbar(); ?>
<?= loginbar(null, $pdo); ?>
</nav>