Add login error message

This commit is contained in:
Jay Trees 2022-02-07 15:14:52 +01:00
parent e230d7ab2b
commit b628de165c
2 changed files with 68 additions and 4 deletions

View file

@ -215,4 +215,62 @@ class Page
</html> </html>
<?php <?php
} }
public function message(string $content = '', string $header = '', string $type = ''): void
{
$containerClasses = array('ui', 'message');
$iconClasses = array('ui', 'icon');
switch ($type) {
case 'error':
$containerClasses[] = 'error icon';
$iconClasses[] = 'exclamation triangle';
break;
case 'warning':
$containerClasses[] = 'warning';
$iconClasses[] = 'exclamation circle';
break;
case 'info':
$containerClasses[] = 'info';
$iconClasses[] = 'info circle';
break;
}
$containerClass = implode(' ', $containerClasses);
$iconClass = implode(' ', $iconClasses);
?>
<div class="<?= $containerClass ?>">
<?php if ($type) { ?>
<i class="<?= $iconClass ?>"></i>
<?php } ?>
<div class="content">
<?php if ($header) { ?>
<div class="header"><?= $header ?></div>
<?php } ?>
<?php if ($content) { ?>
<p><?= $content ?></p>
<?php } ?>
</div>
</div>
<?php
}
public function error(string $content, string $header = ''): void
{
$this->message($content, $header, 'error');
}
public function warning(string $content, string $header = ''): void
{
$this->message($content, $header, 'warning');
}
public function info(string $content, string $header = ''): void
{
$this->message($content, $header, 'info');
}
} }

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* login.php * The user login page.
* *
* @author Jay Trees <github.jay@grandel.anonaddy.me> * @author Jay Trees <github.jay@grandel.anonaddy.me>
*/ */
@ -25,9 +25,9 @@ if (isset($_POST['email'], $_POST['password'])) {
AND `password` = "' . $password . '";' AND `password` = "' . $password . '";'
)->fetch(); )->fetch();
if (false === $user) { $success = false !== $user;
# code...
} else { if ($success) {
$_SESSION['user'] = $user; $_SESSION['user'] = $user;
} }
} }
@ -44,6 +44,12 @@ $page->navigation();
<div class="ui container"> <div class="ui container">
<h1 class="ui header"><?= $page->title ?></h1> <h1 class="ui header"><?= $page->title ?></h1>
<?php
if (!$success) {
$page->error('Invalid credentials!', 'Error');
}
?>
<div class="ui segment"> <div class="ui segment">
<form class="ui form" method="post"> <form class="ui form" method="post">
<div class="field"> <div class="field">