-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.php
More file actions
58 lines (57 loc) · 2.52 KB
/
verify.php
File metadata and controls
58 lines (57 loc) · 2.52 KB
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
<?php
require_once 'backend/connection.php';
//pages that require admin access should require verify.php AFTER setting the variable $using_admin to true:
//example:
//$using_admin = true;
//require_once 'verify.php';
//pages that do NOT need admin access do not need to set $using_admin at all.
if(!empty($_COOKIE['user'])) {
$row_cnt = 0;
//student google login verification
$studentQuery = $db->prepare("SELECT id_token FROM student_data WHERE active = 1");
$studentQuery->execute();
foreach ($studentQuery->get_result() as $row) {
if($row['id_token'] == $_COOKIE['user']) {
if($using_admin !== true) {
$row_cnt++;
} else {
if(isset($_SERVER['HTTP_REFERER'])) {
die('<h1>You do not have permission to access this page. Click <a href="' . $_SERVER['HTTP_REFERER'] .'">here</a> to go back.</h1>');
} else {
die('<h1>You do not have permission to access this page. Click <a href="./">here</a> to go to the main page.</h1>');
}
}
}
}
//admin google login verification
$adminQuery = $db->prepare("SELECT id_token FROM admins");
$adminQuery->execute();
foreach ($adminQuery->get_result() as $row) {
if($row['id_token'] == $_COOKIE['user']) {
$row_cnt++;
}
}
//checking if either query had results, if not, redirect to the login page
if($row_cnt < 1) {
setcookie("user", $_GET['imgurl'], time() - 3600, "/");
setcookie("login", $_GET['imgurl'], time() - 3600, "/");
header('Location: login/?redirect_uri=' . $_SERVER['REQUEST_URI']);
}
} elseif(!empty($_COOKIE['login'])) {
//login verification
$loginQuery = $db->prepare("SELECT login_password FROM login");
$loginQuery->execute();
$loginResult = Array();
$row_cnt = 0;
foreach ($loginQuery->get_result() as $row) {
array_push($loginResult, $row['login_password']);
}
if($_COOKIE['login'] != $loginResult[0]) {
setcookie("user", $_GET['imgurl'], time() - 3600, "/");
setcookie("login", $_GET['imgurl'], time() - 3600, "/");
header('Location: login/?redirect_uri=' . $_SERVER['REQUEST_URI']);
}
} else {
header('Location: login/?redirect_uri=' . $_SERVER['REQUEST_URI']);
}
?>