-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_format.php
80 lines (64 loc) · 2.28 KB
/
login_format.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
<?php
// Teacher Registration for WruD
// © 2014 Department for Education and Child Development
// @Requries - uses the settings from the API for centralisation
require '../api/settings.php';
require '../api/api.fnc.php';
// @Headers
date_default_timezone_set("Australia/Adelaide");
// @Setters
$db = configure_active_database();
$socket = ConnectToDatabase($db) or die("<strong>Error:</strong> couldn't find database! Try again in a few moments.");
// @Getters
$cleanData = array();
$cleanData['emailaddress'] = $socket->real_escape_string(filter_var($_POST['emailaddress'], FILTER_VALIDATE_EMAIL));
// @Inref Functions
function return_failed() {
header('Location: index.php?failed=true');
}
function fix_time($timeString) {
try {
// COOKIE TIME FIXER!!!!!
$correctTimeStamp = date("l, d-M-Y H:i:s T", $timeString);
} catch (Exception $e) {
return_failed();
}
return $correctTimeStamp;
}
// @Build Query
$safeQuery = "SELECT * FROM `users` WHERE `emailaddress`='$cleanData[emailaddress]';";
// @Insert New User
try {
$result = MakeDatabaseQuery($safeQuery, $socket) or return_failed();
$isRows = $result->num_rows;
if ($isRows == 0) {
// Nothing came back in the query.
return_failed();
} else {
// There was a result...
$returnKeys = MakeDatabaseFetch($result, $socket);
if ($returnKeys[emailaddress] == $cleanData[emailaddress]) {
if ($returnKeys[password] == "enabled") {
// Vaid user.
$time = fix_time(time()+9000);
echo '<script type="text/javascript">
document.cookie="emailAddress=' .$returnKeys[emailaddress] . '; expires=' . $time . ';";
document.cookie="firstName=' . $returnKeys[firstname] . '; expires=' . $time . ';";
document.cookie="loginStamped=until; expires=' . $time . ';";
window.location="./dashboard.php";
</script>';
} else {
return_failed();
}
} else {
return_failed();
}
}
if (!result) {
return_failed();
die();
}
} catch (Exception $e) {
return_failed();
die();
}