Add janky ass alerts

This commit is contained in:
William 2021-10-11 09:37:39 +02:00
parent 3ab864a4f9
commit 3cc069773f
3 changed files with 40 additions and 3 deletions

View File

@ -6,6 +6,12 @@ require_once("app/common.php");
// For more options and explanations, check the 'app/template.php' file
$templateParameters["title"] = "Eksempel side";
// Alerts which will be executed from the template
$_SESSION['alert'][] = ['info', 'Eksempel!'];
$_SESSION['alert'][] = ['success', 'Eksempel!'];
$_SESSION['alert'][] = ['warning', 'Eksempel!'];
$_SESSION['alert'][] = ['danger', 'Eksempel!'];
// Include the top of page
require_once("template/_header.php");
?>

View File

@ -6,11 +6,11 @@ if ((isset($_POST['username'])) && (isset($_POST['password']))) {
if (($_POST['username'] === 'VG3') && ($_POST['password'] === '3ELDEA')) {
$_SESSION['logged_in'] = TRUE;
$_SESSION['username'] = $_POST['username'];
$_SESSION['alert'][] = ['info', 'Velkommen '.htmlspecialchars($_SESSION['username']).'!'];
header("Location: index.php");
exit;
exit();
} else {
$loginFormError = "Feil påloggingsinformasjon. Prøv igjen.";
//$loginFormError = "Noe gikk visst galt, prøv igjen senere.";
$_SESSION['alert'][] = ['danger', 'Feil påloggingsinformasjon. Prøv igjen.'];
}
}

View File

@ -53,4 +53,35 @@ if ($templateParameters["render"] === FALSE) {
</div>
<div>
<?php
// is my implementation of alerts janky? maybe...
if ((isset($_SESSION['alert'])) && (count($_SESSION['alert']) > 0)) {
foreach ($_SESSION['alert'] as $alert) {
switch ($alert[0]) {
case 'success':
$prefix = 'Suksess:';
break;
case 'info':
$prefix = 'Info:';
break;
case 'warning':
$prefix = 'Advarsel:';
break;
case 'danger':
$prefix = 'Error:';
break;
default:
$alert[0] = 'danger';
$prefix = 'Ukjent:';
break;
}
echo('<div class="alert alert-'.$alert[0].'"><b>'.$prefix.'</b> '.$alert[1].'</div>');
}
$_SESSION['alert'] = [];
}
?>
<main>