This repository was archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBInit.php
70 lines (67 loc) · 1.71 KB
/
DBInit.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
<?php
//require a CAS log in
require_once 'CAS-1.3.4/CAS.php';
phpCAS::client(CAS_VERSION_2_0,'cas.byu.edu',443,'cas');
$auth = phpCAS::checkAuthentication();
if(!file_exists('database.sqlite'))
{
//echo "This API is to clear an exsising database. There currenlty is no database " .
// "file found. Go to the home page, which will set up the initial database";
require_once "DBConnect.php";
$db = new MyDB();
echo json_encode(array("status"=>"Successfully created the DB"));
exit();
}
else
{
if (isset($_REQUEST['logout'])) {
phpCAS::logout();
}
if (isset($_REQUEST['login'])) {
phpCAS::forceAuthentication();
}
if($auth)
{
try
{
require_once "DBConnect.php";
//check the supplied userID is the same as the logged in user
if(verifyTA(phpCAS::getUser()))
{
if($_POST["confirmed"] == true)
{
$r = getNameStatus(phpCAS::getUser());
$name = $r["name"];
//a TA has authorized the reseting of the database
if(unlink('database.sqlite'))
{
$db = new MyDB();
updateName(phpCAS::getUser(), $name);
echo json_encode(array("status"=>"Successfully re-created the DB"));
}
else
echo json_encode(array("status"=>"Error removing old DB"));
}
else
{
echo json_encode(array("status"=>"reset not confirmed"));
}
}
else
{
echo json_encode(array("status"=>"You are not authorized to make that call"));
}
}
catch(CAS_OutOfSequenceBeforeClientException $e)
{
echo json_encode(array("status"=>"Error getting netID from BYU"));
}
} else { //go to login page!
?>
<script language="javascript">
window.location.href = "?login="
</script>
<?php
}
}
?>