-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.php
94 lines (92 loc) · 2.27 KB
/
auth.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
<?php
function validate_param()
{
return isset($_GET["token"]) && $_GET["token"] && isset($_GET["expiry"]) && $_GET["expiry"] && isset($_GET["page"]) && $_GET["page"];
}
if (!validate_param()) {
echo "
<script>
alert('Parameter tidak valid');
history.back();
</script>";
die;
}
require_once('api/get_request.php');
$userData = json_decode(http_request_with_auth("https://account.lumintulogic.com/api/user.php", $_GET['token']));
if (!$userData) {
echo "
<script>
alert('Gagal mendapatkan data user');
history.back();
</script>";
die;
}
session_start();
// var_dump($userData);
// die();
$_SESSION['user_data'] = $userData;
$_SESSION['expiry'] = $_GET['expiry'];
setcookie('X-LUMINTU-REFRESHTOKEN', $_GET['token'], strtotime($_GET['expiry']));
// var_dump($_SESSION);
// var_dump($_COOKIE['X-LUMINTU-REFRESHTOKEN']);
// // die();
if (!isset($_SESSION['user_data'])) {
echo "
<script>
alert('Gagal set Session');
history.back();
</script>";
die;
}
if (!isset($_COOKIE['X-LUMINTU-REFRESHTOKEN'])) {
echo "
<script>
alert('Gagal set Cookie');
history.back();
</script>";
die;
}
switch ($_SESSION["user_data"]->{'user'}->{'role_id'}) {
case 1:
// Admin
break;
case 2:
// Mentor
switch ($_GET['page']) {
case 'index':
# code...
header("location: Role/Mentor/index.php");
break;
case 'assignment':
header("location: Role/Mentor/assignment.php?subject_id=" . $_GET['subject_id']);
break;
default:
echo "
<script>
history.back();
</script>";
break;
}
break;
case 3:
// Student
switch ($_GET['page']) {
case 'index':
# code...
header("location: Role/Student/index.php");
break;
case 'score':
header("location: Role/Student/score.php");
break;
default:
# code...
break;
}
break;
default:
echo "
<script>
history.back();
</script>";
break;
}