Spaces:
Running
Running
Upload admin_users.html
Browse files
src/apps/templates/admin_users.html
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
@@ -17,39 +18,71 @@
|
|
| 17 |
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
|
| 18 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 19 |
}
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
.table-wrapper {
|
| 22 |
overflow-x: auto;
|
| 23 |
}
|
|
|
|
| 24 |
table {
|
| 25 |
width: 100%;
|
| 26 |
border-collapse: collapse;
|
| 27 |
margin-top: 1rem;
|
| 28 |
color: white;
|
| 29 |
}
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
padding: 1.25rem;
|
| 32 |
text-align: left;
|
| 33 |
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
| 34 |
}
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
color: #D6BCFA;
|
| 38 |
font-weight: 600;
|
| 39 |
text-transform: uppercase;
|
| 40 |
font-size: 0.85rem;
|
| 41 |
letter-spacing: 0.05em;
|
| 42 |
}
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
.badge {
|
| 45 |
padding: 0.35rem 0.75rem;
|
| 46 |
border-radius: 9999px;
|
| 47 |
font-size: 0.75rem;
|
| 48 |
font-weight: 500;
|
| 49 |
}
|
| 50 |
-
|
| 51 |
-
.badge-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
.back-btn {
|
| 54 |
display: inline-block;
|
| 55 |
margin-bottom: 1rem;
|
|
@@ -57,9 +90,13 @@
|
|
| 57 |
text-decoration: none;
|
| 58 |
font-size: 0.9rem;
|
| 59 |
}
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
| 61 |
</style>
|
| 62 |
</head>
|
|
|
|
| 63 |
<body class="dark" style="background-color: #030303;">
|
| 64 |
<div class="admin-container">
|
| 65 |
<a href="/" class="back-btn">← Back to Dashboard</a>
|
|
@@ -74,12 +111,15 @@
|
|
| 74 |
try {
|
| 75 |
const response = await fetch('/api/admin/users');
|
| 76 |
if (!response.ok) {
|
| 77 |
-
if (response.status === 403
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
throw new Error('Failed to fetch data');
|
| 80 |
}
|
| 81 |
const users = await response.json();
|
| 82 |
-
|
| 83 |
let html = `
|
| 84 |
<table>
|
| 85 |
<thead>
|
|
@@ -94,7 +134,7 @@
|
|
| 94 |
</thead>
|
| 95 |
<tbody>
|
| 96 |
`;
|
| 97 |
-
|
| 98 |
users.forEach(user => {
|
| 99 |
const badgeClass = user.role === 'Admin' ? 'badge-Admin' : 'badge-User';
|
| 100 |
html += `
|
|
@@ -108,15 +148,16 @@
|
|
| 108 |
</tr>
|
| 109 |
`;
|
| 110 |
});
|
| 111 |
-
|
| 112 |
html += `</tbody></table>`;
|
| 113 |
document.getElementById('usersList').innerHTML = users.length > 0 ? html : '<p style="text-align:center; padding: 2rem;">No users found.</p>';
|
| 114 |
} catch (err) {
|
| 115 |
document.getElementById('usersList').innerHTML = `<div style="text-align:center; padding: 2rem;"><p style="color:#ef4444; margin-bottom: 0.5rem;">🚨 Error: ${err.message}</p><a href="/login?role=Admin" style="color:#9b87f5; text-decoration:none;">Login as Admin</a></div>`;
|
| 116 |
}
|
| 117 |
}
|
| 118 |
-
|
| 119 |
fetchUsers();
|
| 120 |
</script>
|
| 121 |
</body>
|
| 122 |
-
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
+
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
| 18 |
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
|
| 19 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 20 |
}
|
| 21 |
+
|
| 22 |
+
h2 {
|
| 23 |
+
text-align: center;
|
| 24 |
+
margin-bottom: 2rem;
|
| 25 |
+
font-size: 2rem;
|
| 26 |
+
color: #9b87f5;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
.table-wrapper {
|
| 30 |
overflow-x: auto;
|
| 31 |
}
|
| 32 |
+
|
| 33 |
table {
|
| 34 |
width: 100%;
|
| 35 |
border-collapse: collapse;
|
| 36 |
margin-top: 1rem;
|
| 37 |
color: white;
|
| 38 |
}
|
| 39 |
+
|
| 40 |
+
th,
|
| 41 |
+
td {
|
| 42 |
padding: 1.25rem;
|
| 43 |
text-align: left;
|
| 44 |
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
| 45 |
}
|
| 46 |
+
|
| 47 |
+
th {
|
| 48 |
+
background: rgba(155, 135, 245, 0.2);
|
| 49 |
color: #D6BCFA;
|
| 50 |
font-weight: 600;
|
| 51 |
text-transform: uppercase;
|
| 52 |
font-size: 0.85rem;
|
| 53 |
letter-spacing: 0.05em;
|
| 54 |
}
|
| 55 |
+
|
| 56 |
+
tr:hover {
|
| 57 |
+
background: rgba(255, 255, 255, 0.03);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
.badge {
|
| 61 |
padding: 0.35rem 0.75rem;
|
| 62 |
border-radius: 9999px;
|
| 63 |
font-size: 0.75rem;
|
| 64 |
font-weight: 500;
|
| 65 |
}
|
| 66 |
+
|
| 67 |
+
.badge-Admin {
|
| 68 |
+
background: rgba(239, 68, 68, 0.2);
|
| 69 |
+
color: #f87171;
|
| 70 |
+
border: 1px solid rgba(239, 68, 68, 0.2);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.badge-User {
|
| 74 |
+
background: rgba(59, 130, 246, 0.2);
|
| 75 |
+
color: #60a5fa;
|
| 76 |
+
border: 1px solid rgba(59, 130, 246, 0.2);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.loading {
|
| 80 |
+
text-align: center;
|
| 81 |
+
font-style: italic;
|
| 82 |
+
padding: 2rem;
|
| 83 |
+
color: #a1a1aa;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
.back-btn {
|
| 87 |
display: inline-block;
|
| 88 |
margin-bottom: 1rem;
|
|
|
|
| 90 |
text-decoration: none;
|
| 91 |
font-size: 0.9rem;
|
| 92 |
}
|
| 93 |
+
|
| 94 |
+
.back-btn:hover {
|
| 95 |
+
text-decoration: underline;
|
| 96 |
+
}
|
| 97 |
</style>
|
| 98 |
</head>
|
| 99 |
+
|
| 100 |
<body class="dark" style="background-color: #030303;">
|
| 101 |
<div class="admin-container">
|
| 102 |
<a href="/" class="back-btn">← Back to Dashboard</a>
|
|
|
|
| 111 |
try {
|
| 112 |
const response = await fetch('/api/admin/users');
|
| 113 |
if (!response.ok) {
|
| 114 |
+
if (response.status === 403 || response.status === 401) {
|
| 115 |
+
// For safety, immediately transfer unauthenticated users to the secure login portal
|
| 116 |
+
window.location.href = '/login?role=Admin';
|
| 117 |
+
return;
|
| 118 |
+
}
|
| 119 |
throw new Error('Failed to fetch data');
|
| 120 |
}
|
| 121 |
const users = await response.json();
|
| 122 |
+
|
| 123 |
let html = `
|
| 124 |
<table>
|
| 125 |
<thead>
|
|
|
|
| 134 |
</thead>
|
| 135 |
<tbody>
|
| 136 |
`;
|
| 137 |
+
|
| 138 |
users.forEach(user => {
|
| 139 |
const badgeClass = user.role === 'Admin' ? 'badge-Admin' : 'badge-User';
|
| 140 |
html += `
|
|
|
|
| 148 |
</tr>
|
| 149 |
`;
|
| 150 |
});
|
| 151 |
+
|
| 152 |
html += `</tbody></table>`;
|
| 153 |
document.getElementById('usersList').innerHTML = users.length > 0 ? html : '<p style="text-align:center; padding: 2rem;">No users found.</p>';
|
| 154 |
} catch (err) {
|
| 155 |
document.getElementById('usersList').innerHTML = `<div style="text-align:center; padding: 2rem;"><p style="color:#ef4444; margin-bottom: 0.5rem;">🚨 Error: ${err.message}</p><a href="/login?role=Admin" style="color:#9b87f5; text-decoration:none;">Login as Admin</a></div>`;
|
| 156 |
}
|
| 157 |
}
|
| 158 |
+
|
| 159 |
fetchUsers();
|
| 160 |
</script>
|
| 161 |
</body>
|
| 162 |
+
|
| 163 |
+
</html>
|