🎨 Don't use header() to redirect to /login

Signed-off-by: Luke Tainton <luke@tainton.uk>
This commit is contained in:
2020-08-04 18:29:23 +01:00
parent d464fef3a8
commit b68f299021
5 changed files with 118 additions and 144 deletions

View File

@@ -8,6 +8,11 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#563d7c"> <meta name="theme-color" content="#563d7c">
<?php
if (!is_logged_in()) {
echo("<meta http-equiv='refresh' content='0; url=" . $_ENV['APP_URL'] . "/login' />");
}
?>
<title><?php echo( $PAGE_TITLE ); ?></title> <title><?php echo( $PAGE_TITLE ); ?></title>
<!-- Bootstrap core CSS --> <!-- Bootstrap core CSS -->

View File

@@ -3,7 +3,6 @@
require_once __DIR__ . "/../includes/prereqs.php"; require_once __DIR__ . "/../includes/prereqs.php";
require_once __DIR__ . "/../includes/header.php"; require_once __DIR__ . "/../includes/header.php";
if (is_signed_in()) {
// Get user's own tickets // Get user's own tickets
try { try {
$user_tickets_stmt = "SELECT uuid, id, title, description, status FROM tickets WHERE created_by=:uuid"; $user_tickets_stmt = "SELECT uuid, id, title, description, status FROM tickets WHERE created_by=:uuid";
@@ -28,9 +27,6 @@
echo("Error: " . $e->getMessage()); echo("Error: " . $e->getMessage());
} }
$user_tickets_sub = 0; // Force 'no subbed tickets' msg until the code works
}
function get_sub_ticket($db, $ticket_uuid) { function get_sub_ticket($db, $ticket_uuid) {
try { try {
$stmt = "SELECT * FROM tickets WHERE uuid=:uuid"; $stmt = "SELECT * FROM tickets WHERE uuid=:uuid";
@@ -77,21 +73,12 @@
is the one-stop shop for all of your IT-related needs. Let us know how we can help you by opening a request. is the one-stop shop for all of your IT-related needs. Let us know how we can help you by opening a request.
</p> </p>
<p> <p>
<?php
if (is_signed_in()) {
echo("
<a href='/new' class='btn btn-primary my-2'>Create a request</a> <a href='/new' class='btn btn-primary my-2'>Create a request</a>
<a href='/open' class='btn btn-secondary my-2'>View existing requests</a> <a href='/open' class='btn btn-secondary my-2'>View existing requests</a>
");
} else {
echo("<b>Please log in to create or view tickets.</b>");
}
?>
</p> </p>
</div> </div>
</section> </section>
<?php if (is_signed_in()) { ?>
<section> <section>
<div class="card mx-auto" style="width: 80%;"> <div class="card mx-auto" style="width: 80%;">
<div class="card-header"> <div class="card-header">
@@ -129,7 +116,6 @@
</div> </div>
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
<?php <?php
// if ($user_tickets_sub == 0) {
if (count($sub_tickets_result) == 0) { if (count($sub_tickets_result) == 0) {
echo("<center><b>No subscribed tickets</b></center>"); echo("<center><b>No subscribed tickets</b></center>");
} else { } else {
@@ -154,7 +140,6 @@
</ul> </ul>
</div> </div>
</section> </section>
<?php } ?>
</main> </main>

View File

@@ -3,10 +3,6 @@
require_once __DIR__ . "/../includes/prereqs.php"; require_once __DIR__ . "/../includes/prereqs.php";
require_once __DIR__ . "/../includes/header.php"; require_once __DIR__ . "/../includes/header.php";
if (!is_signed_in()) {
header('Location: /login');
}
// If form submitted, save to database // If form submitted, save to database
if($_SERVER['REQUEST_METHOD'] == 'POST') { if($_SERVER['REQUEST_METHOD'] == 'POST') {
try { try {
@@ -69,7 +65,7 @@
<section> <section>
<div class="card mx-auto" style="width: 50%;"> <div class="card mx-auto" style="width: 50%;">
<form action="/new" method="post" enctype="multipart/form-data"> <form style="padding: 2%" action="/new" method="post" enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
<label for="title">Title: </label> <label for="title">Title: </label>
<input type="text" class="form-control" id="title"> <input type="text" class="form-control" id="title">

View File

@@ -2,10 +2,6 @@
$PAGE_NAME = "Open requests"; $PAGE_NAME = "Open requests";
require_once __DIR__ . "/../includes/prereqs.php"; require_once __DIR__ . "/../includes/prereqs.php";
require_once __DIR__ . "/../includes/header.php"; require_once __DIR__ . "/../includes/header.php";
if (!is_signed_in()) {
header('Location: /login');
}
?> ?>

View File

@@ -3,7 +3,6 @@
require_once __DIR__ . "/../includes/prereqs.php"; require_once __DIR__ . "/../includes/prereqs.php";
require_once __DIR__ . "/../includes/header.php"; require_once __DIR__ . "/../includes/header.php";
if (is_signed_in()) {
// Get ticket // Get ticket
try { try {
$ticket_stmt = "SELECT * FROM tickets WHERE uuid=:uuid"; $ticket_stmt = "SELECT * FROM tickets WHERE uuid=:uuid";
@@ -39,7 +38,6 @@
} else { } else {
$is_authorised = false; $is_authorised = false;
} }
}
?> ?>
@@ -48,7 +46,7 @@
<!-- Begin page content --> <!-- Begin page content -->
<main role="main" class="flex-shrink-0"> <main role="main" class="flex-shrink-0">
<?php if (is_signed_in() && $is_authorised == true) { ?> <?php if ($is_authorised == true) { ?>
<section class="jumbotron text-center"> <section class="jumbotron text-center">
<div class="container"> <div class="container">
<h1><?php echo($request['title']); ?></h1> <h1><?php echo($request['title']); ?></h1>
@@ -64,18 +62,12 @@
</p> </p>
</div> </div>
</section> </section>
<?php } else if (is_signed_in() && $is_authorised == false) { ?> <?php } else if ($is_authorised == false) { ?>
<section class="jumbotron text-center"> <section class="jumbotron text-center">
<div class="container"> <div class="container">
<h1>You are not authorised to see this page.</h1> <h1>You are not authorised to see this page.</h1>
</div> </div>
</section> </section>
<?php } else { ?>
<section class="jumbotron text-center">
<div class="container">
<h1>You need to be logged in to see this page.</h1>
</div>
</section>
<?php } ?> <?php } ?>
</main> </main>