-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
102 lines (95 loc) · 3.47 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* A simple, clean and secure PHP Login Script / MINIMAL VERSION
* For more versions (one-file, advanced, framework-like) visit http://www.php-login.net
*
* Uses PHP SESSIONS, modern password-hashing and salting and gives the basic functions a proper login system needs.
*
* @author Panique
* @link https://github.com/panique/php-login-minimal/
* @license http://opensource.org/licenses/MIT MIT License
*/
// checking for minimum PHP version
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
// if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
// (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
require_once("../libraries/password_compatibility_library.php");
}
// include the configs / constants for the database connection
require_once("../config/db.php");
// load the Message Handler
// This will be called at the top of every page.
require_once("classes/MessageHandler.php");
$messageHandler = new MessageHandler();
// load the classes
require_once("classes/Login.php");
// create a login object. when this object is created, it will do all login/logout stuff automatically
// so this single line handles the entire login process. in consequence, you can simply ...
$login = new Login();
if ($login->errors) {
foreach ($login->errors as $error) {
$messageHandler->errors[] = $error;
}
}
if ($login->messages) {
foreach ($login->messages as $message) {
$messageHandler->messages[] = $message;
}
}
// ... ask if we are logged in here:
if ($login->isUserLoggedIn() == true) {
// The user is logged in.
// Make sure that Username instance exists, or else they need to log out.
if ($_SESSION['user_name'] == false) {
header("location:index.php?logout");
}
// With an empty status, we go to either SentData or EnterContacts.
// This depends upon the results of StartApp, all in its constructor.
require_once("classes/StartApp.php");
$startApp = new StartApp();
if ($startApp->errors) {
foreach ($startApp->errors as $error) {
$messageHandler->errors[] = $error;
}
}
if ($startApp->messages) {
foreach ($startApp->messages as $message) {
$messageHandler->messages[] = $message;
}
}
if (empty($_SESSION['status']))
{
include("views/error.php");
return;
}
include("views/contest.php");
if (false)
{
if (!isset($_COOKIE["contestData"]))
{
require_once("classes/SentData.php");
$sentData = new SentData();
if ($sentData->errors) {
foreach ($sentData->errors as $error) {
$messageHandler->errors[] = $error;
}
}
if ($sentData->messages) {
foreach ($sentData->messages as $message) {
$messageHandler->messages[] = $message;
}
}
if (!empty($messageHandler->errors))
{
include("views/error.php");
return;
}
}
}
} else {
// the user is not logged in. you can do whatever you want here.
// for demonstration purposes, we simply show the "you are not logged in" view.
include("views/not_logged_in.php");
}