-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.html
89 lines (80 loc) · 3.11 KB
/
dashboard.html
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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dashboard</title>
<link rel="icon" href="assets/img/dashboard/icon.png" />
<link rel="stylesheet" href="assets/css/login-page/page.css" />
<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
</head>
<style>
body {
padding: 20px;
display: block;
}
#container {
background-color: white;
box-shadow: 0 0 30px #c6c7c8;
padding: 20px;
}
</style>
<body>
<div id="container">
<h1>This is a sample dashboard</h1>
<span id="details" class="fa fa-spinner fa-pulse"></span>
</div>
</body>
<script>
const href = window.location.href;
const query_pos = href.indexOf('?');
if (query_pos == -1) {
alert("No user ID specified");
location.replace("index.html");
}
const userID = href.substr(query_pos + 4);
const details_box = document.getElementById("details");
var credentials = sessionStorage.getItem("users") || localStorage.getItem("users");
if (credentials == null) {
alert("You are not logged in. You will be redirected to the login page...");
location.replace("login-page.html");
}
credentials = JSON.parse(credentials);
var id_index = -1;
for (i in credentials) {
if (credentials[i].id == userID) {
id_index = i;
break;
}
}
if (id_index == -1) {
alert("You are not logged in. You will be redirected to the login page...");
location.replace("login-page.html");
}
const request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
const data = JSON.parse(this.responseText);
if (!data.db_conn_succ) {
details_box.innerHTML = "Could not connect to database";
details_box.style.color = "red";
details_box.classList.remove("fa", "fa-spinner", "fa-pulse");
return;
}
if (data.login_success) {
details_box.innerHTML = `<strong>Username:</strong> ${data.username}<br>
<strong>Email ID:</strong> ${data.email}`;
} else {
alert("You are not logged in. You will be redirected to the login page...");
location.replace("login-page.html");
}
} else details_box.innerHTML = "<strong style='color:red'>Something went wrong</strong>";
details_box.classList.remove("fa", "fa-spinner", "fa-pulse");
}
};
request.open("POST", "dashboard-backend.php");
request.send(JSON.stringify(credentials[id_index]));
</script>
</html>