Admin page adjustment

This commit is contained in:
Chris Smith
2019-03-15 21:04:58 -05:00
parent 4db63fb7d4
commit 0b5987a858
3 changed files with 43 additions and 1 deletions

View File

@@ -39,6 +39,31 @@ $router->set404(function () {
echo '404, route not found!'; echo '404, route not found!';
}); });
$router->before('GET|POST', '/admin/.*', function() {
session_start();
if (!isset($_SESSION['user'])) {
header('location: /auth/login');
exit();
}
});
$router->get('/auth/login', function() {
include 'views/common/head.php';
include 'views/admin-login.php';
include 'views/common/footer.php';
});
$router->post('/auth/login', function() {
if (($_POST['username'] == $_SERVER['ADMIN_USER']) && ($_POST['password'] == $_SERVER['ADMIN_PASS'])) {
session_start();
$_SESSION['user'] = $_POST['username'];
header('Location: /admin/orders');
}else{
header('Location: /auth/login?alert=error');
}
});
// Static route: / (homepage) // Static route: / (homepage)
$router->get('/', function () { $router->get('/', function () {
$settings = \RedBeanPHP\R::load('settings', 1); $settings = \RedBeanPHP\R::load('settings', 1);

17
views/admin-login.php Normal file
View File

@@ -0,0 +1,17 @@
<h1>Admin Login</h1>
<div class="row">
<form method="POST">
<div class="input-group form-group">
<input type="text" name="username" class="form-control" placeholder="username">
</div>
<div class="input-group form-group">
<input type="password" name="password" class="form-control" placeholder="password">
</div>
<div class="form-group">
<input type="submit" value="Login" class="btn btn-primary">
</div>
</form>
<br/>
<br/>
</div>

View File

@@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div class="col-md-12 order-md-1"> <div class="col-md-12 order-md-1">
<h3 class="mb-3">Orders <a href="/admin/orders/export" class="btn btn-primary">Order Export</a><a href="/admin/guests/export" class="btn btn-primary">Guest Export</a></h3> <h3 class="mb-3">Orders <a href="/admin/orders/export" class="btn btn-primary">Order Export</a>&nbsp;<a href="/admin/guests/export" class="btn btn-primary">Guest Export</a></h3>
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>