-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.php
313 lines (281 loc) · 8.12 KB
/
home.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<?php
require_once 'UI/styleIncludes.php'; ?>
<title>Login</title>
</head>
<body>
<?php
require_once 'requires.php';
require_once 'UI/navBar.php'; ?>
<form id="loginForm" class="form-signin" action="home.php" method="post">
<h2 class="form-signin-heading">Log in</h2>
<div id="alertLoginIncorrectCred" class="alert alert-danger">
<strong><i class="fa fa-warning"></i>Unsuccessful Login</strong> The email or password you entered is incorrect
</div>
<div id="alertPending" class="alert alert-warning">
<strong><i class="fa fa-warning"></i>Pending</strong> Your account is currently Pending Approval
</div>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" name="AUTH_EMAIL" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" name="AUTH_PASSWORD" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
</form>
</body>
</html>
<?php
if(isset($_SESSION['user']) && !isset($_POST['LOGOUT'])){
displayWelcomePanel($user);
}
/* If the a session user variable is not set and AUTH_USERNAME and AUTH_PASSWORD have been posted sign in the user */
if (!isset($_SESSION['user']) && isset($_POST['AUTH_EMAIL']) && isset($_POST['AUTH_PASSWORD']))
{
$dbMan = new DatabaseManager();
if(!$dbMan->establishConnection()){
//database connection error
return;
}
//create new user instance
$user = new User($_POST['AUTH_EMAIL']);
$user->password = $_POST['AUTH_PASSWORD'];
//check login credentials
$email_temp = mysql_entities_fix_string($dbMan->connection, $_POST['AUTH_EMAIL']);
$request = new Request('SELECT *', 'se_Users');
$request->addParameter('email', $email_temp);
$request->transformCommand();
$loginResults = $dbMan->executeQuery($request);
//server error
if($loginResults == null){
//request was unsuccessful
}
else if($loginResults -> num_rows){
//user exsists
$row = $loginResults -> fetch_array(MYSQLI_NUM);
$loginResults -> close();
$user->hashedPassword = hash('ripemd128', "g!cT$user->email$user->password");
//password correct
if($user->hashedPassword == $row[4])
{
//sucessful login
if($row[6] == 'ACTIVE'){
$user->id = $row[0];
$user->firstName = $row[1];
$user->lastName = $row[2];
$user->email = $row[3];
$user->type = $row[5];
$_SESSION['user'] = $user;
displayWelcomePanel($user);
showNavBarItems($user);
}
else{
echo <<<_END
<script type="text/javascript">
$(document).ready(function(){
$('#loginForm').show();
$('#alertPending').show();
$('#requestAccount').show();
});
</script>
_END;
}
}
else{
//incorrect password
echo <<<_END
<script type="text/javascript">
$(document).ready(function(){
$('#loginForm').show();
$('#alertLoginIncorrectCred').show();
$('#requestAccount').show();
});
</script>
_END;
}
}
else{
//user does not exsist
echo <<<_END
<script type="text/javascript">
$(document).ready(function(){
$('#loginForm').show();
$('#alertLoginIncorrectCred').show();
$('#requestAccount').show();
});
</script>
_END;
}
}
//user clicked logout button
else if(isset($_POST['LOGOUT'])){
destroy_session_and_data();
echo <<<_END
<script type="text/javascript">
$(document).ready(function(){
$('#loginForm').show();
$('#requestAccount').show();
$('#signOut').hide();
$('#userAccounts').hide();
$('#myAccount').hide();
$('#query').hide();
});
</script>
_END;
}
//otherwise - not logged in
else if(!isset($_SESSION['user']))
{
echo <<<_END
<script type="text/javascript">
$(document).ready(function(){
$('#loginForm').show();
$('#requestAccount').show();
});
</script>
_END;
}
function mysql_entities_fix_string($connection, $string)
{
return htmlentities(mysql_fix_string($connection, $string));
}
function mysql_fix_string($connection, $string)
{
if(get_magic_quotes_gpc()) $string = stripslashes($string);
return $connection -> real_escape_string($string);
}
function destroy_session_and_data()
{
$_SESSION = array();
session_destroy();
}
function displayWelcomePanel($user){
if($user->type == 'SUPER_USER'){ $type = 'Super User'; $sidePadding = '150px';}
else if($user->type == 'ADMINISTRATOR'){ $type = 'Administrator'; $sidePadding = '250px';}
else{ $type = 'General User'; $sidePadding = '300px';}
$width = 50;
echo <<<_END
<div class="contents home">
<h1>Welcome, $user->firstName $user->lastName </h1>
<h4>$type</h4>
<div class="table" id="actionTiles" style="padding: 0 $sidePadding">
<div class="table-row">
_END;
if($user->type == 'SUPER_USER'){
$width = 25;
$pendingAccounts = getNumberOfPendingAccounts();
echo <<<_END
<div class="table-cell" style="width: $width%">
<a href="pendingAccounts.php">
<div class="tile">
<div class="table-row">
<div class="top table-cell">
<i class="fa fa-tasks"></i>
</div>
</div>
<div class="table-row">
<div class="bottom table-cell">
<div>Pending Accounts</div>
_END;
if($pendingAccounts > 0){
echo '<div><span class="badge">' . $pendingAccounts . ' </span></div>';
}
echo <<<_END
</div>
</div>
</div>
</a>
</div>
<div class="table-cell" style="width: $width%">
<a href="manageUserRestrictions.php">
<div class="tile">
<div class="table-row">
<div class="top table-cell">
<i class="fa fa-warning"></i>
</div>
</div>
<div class="table-row">
<div class="bottom table-cell">
<div>Pending Restrictions</div>
</div>
</div>
</div>
</a>
</div>
_END;
}
else if($user->type == 'ADMINISTRATOR'){
$width = 33;
echo <<<_END
<div class="table-cell" style="width: $width%">
<a href="manageUserRestrictions.php">
<div class="tile">
<div class="table-row">
<div class="top table-cell">
<i class="fa fa-ban"></i>
</div>
</div>
<div class="table-row">
<div class="bottom table-cell">
<div>Manage Restrictions</div>
</div>
</div>
</div>
</a>
</div>
_END;
}
echo <<<_END
<div class="table-cell" style="width: $width%">
<a href="manageAccount.php">
<div class="tile">
<div class="table-row">
<div class="top table-cell">
<i class="fa fa-user"></i>
</div>
</div>
<div class="table-row">
<div class="bottom table-cell">
<div>Manage Account</div>
</div>
</div>
</div>
</a>
</div>
<div class="table-cell" style="width: $width%">
<a href="query.php">
<div class="tile">
<div class="table-row">
<div class="top table-cell">
<i class="fa fa-search"></i>
</div>
</div>
<div class="table-row">
<div class="bottom table-cell">
<div>Query</div>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</div>
_END;
}
function getNumberOfPendingAccounts(){
$dbMan = new DatabaseManager();
if(!$dbMan->establishConnection()){
//database connection error
return;
}
$request = new Request('SELECT *', 'se_Users');
$request->addParameter('status', 'PENDING_APPROVAL');
$request->transformCommand();
$results = $dbMan->executeQuery($request);
if($results == null){
//request failed
}
return $rows = $results->num_rows;
}
?>