-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
57 lines (51 loc) · 1.63 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
<?php
session_start();
require_once('class/general_tools.class.php');
require_once('class/login.class.php');
$login = new login();
$general_tools = new general_tools();
$general_tools->RequireSSL();
$tok = 'inspireLoginToken';
if (isset($_GET['logout'])) {
$login->Logout();
unset($login);
header("Location: index.php?error=Logged%20Out");
exit();
}
// If there's a valid cookie, store the cookie data in the session variable
if ($login->HasValidCookie() || isset($_SESSION[login::SESSION_NAME])) {
$data = $login->DecryptData(isset($_SESSION[login::SESSION_NAME]) ? $_SESSION[login::SESSION_NAME] : $login->GetCookie());
$postVars['email'] = $data->email;
$postVars['hash'] = $data->hash;
if ($login->ValidateCredentials($postVars)) {
DoLogin($login);
}
}
if (isset($_POST['validate'])) { // Validate credentials
$err = '';
if (empty($_SESSION[$tok]) || empty($_POST[$tok]) || $_POST[$tok] !== $_SESSION[$tok]) {
// The form didn't originate from us.
$err = 'Invalid%20source';
} else {
if ($login->ValidateCredentials($_POST)) {
DoLogin($login);
} else {
$err = 'Invalid%20Credentials';
}
}
unset($_SESSION[$tok]);
header("Location: index.php?error=$err");
} else { // Prompt to log in
$_SESSION[$tok] = md5(time() . rand(1,00));
echo $login->LoginForm($_SESSION[$tok]);
}
function DoLogin($login) {
$login->user->UpdateLastLogin();
$_SESSION[login::SESSION_NAME] = $login->EncryptData();
if (isset($_POST['rememberme']) && $_POST['rememberme'] == 1) {
$login->SetCookie();
}
require_once('class/inspire.class.php');
(new inspire())->getContent($login);
exit();
}