-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·83 lines (76 loc) · 2.87 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once "php/index_start.inc.php";
global $database, $title;
session_start();
$loginEnabled = !isLoginDisabled();
if (isset($_GET['logout']) || (isset($_SESSION['key']) && !checkKeyVotes($_SESSION['key']))) {
logout($_SESSION['key']);
header("Location: index.php");//reload
die();
}
$formWasSubmitted = $_SERVER['REQUEST_METHOD'] === 'POST';
if ($formWasSubmitted && !isset($_SESSION['key'])) {
if (isset($_POST['key'])) {
$key = $_POST['key'];
if ($loginEnabled) {
if (!empty($key)) {
if (checkKey($key) && checkKeyVotes($key)) {
$statement = $database->getConnection()->query("SELECT * FROM `candidates_types` ORDER BY ID ASC");
$candidates_types = $statement->fetchAll(PDO::FETCH_ASSOC);
if (!empty($candidates_types)) {
$_SESSION['key'] = $key;
updateKeyUsedTime($key);
session_regenerate_id();
header("Location: voting.php?type=" . $candidates_types[0]->ID);
die();
}
$errorMessage = "Es sind keine Wahlen definiert!";
}
} else {
$errorMessage = "Dieser Key ist ungültig!";
}
} else {
$errorMessage = "Das Login ist zurzeit deaktiviert!";
}
} else {
$errorMessage = "Key konnte nicht überprüft werden!!";
}
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<?php require_once "php/imports.inc.php"; ?>
</head>
<body>
<main>
<section>
<h1 class="title"><?= (!isset($_SESSION['key']) ? 'Willkommen zur ' : "") . $title ?></h1>
<?php if (isset($errorMessage)) { ?>
<div class="message error"><?= $errorMessage ?></div>
<?php } ?>
<?php if (!isset($_SESSION['key'])) { ?>
<div class="login">
<form class="big-form" method="post">
<label class="credentials">
<input id="key" type="text" placeholder="Key eingeben" name="key" required
autocomplete="off" autofocus/>
</label>
<button class="button" type="submit">Key prüfen</button>
</form>
</div>
<?php } else { ?>
<div class="text-center container">
<h3>Mit diesem Key wurde noch nicht (fertig) gewählt!</h3>
<p>Wenn du einen neuen Key eingibst wird dieser Key ungültig!</p>
</div>
<div class="button-group">
<a class="button" href="index.php?logout=1">< Neuen Key eingeben</a>
<a class="button" href="voting.php">Wählen fortsetzen ></a>
</div>
<?php } ?>
</section>
</main>
<?php include "php/footer.inc.php"; ?>
</body>
</html>