Spaces:
Running
Running
File size: 5,548 Bytes
678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 76f689b 678d065 7e698ac 76f689b 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac 678d065 7e698ac | 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - Users List</title>
<link rel="stylesheet" href="/static/css/styles.css">
<style>
.admin-container {
max-width: 1200px;
margin: 40px auto;
padding: 2rem;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border-radius: 12px;
color: white;
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
border: 1px solid rgba(255, 255, 255, 0.1);
}
h2 {
text-align: center;
margin-bottom: 2rem;
font-size: 2rem;
color: #9b87f5;
}
.table-wrapper {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
color: white;
}
th,
td {
padding: 1.25rem;
text-align: left;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
th {
background: rgba(155, 135, 245, 0.2);
color: #D6BCFA;
font-weight: 600;
text-transform: uppercase;
font-size: 0.85rem;
letter-spacing: 0.05em;
}
tr:hover {
background: rgba(255, 255, 255, 0.03);
}
.badge {
padding: 0.35rem 0.75rem;
border-radius: 9999px;
font-size: 0.75rem;
font-weight: 500;
}
.badge-Admin {
background: rgba(239, 68, 68, 0.2);
color: #f87171;
border: 1px solid rgba(239, 68, 68, 0.2);
}
.badge-User {
background: rgba(59, 130, 246, 0.2);
color: #60a5fa;
border: 1px solid rgba(59, 130, 246, 0.2);
}
.loading {
text-align: center;
font-style: italic;
padding: 2rem;
color: #a1a1aa;
}
.back-btn {
display: inline-block;
margin-bottom: 1rem;
color: #9b87f5;
text-decoration: none;
font-size: 0.9rem;
}
.back-btn:hover {
text-decoration: underline;
}
</style>
</head>
<body class="dark" style="background-color: #030303;">
<div class="admin-container">
<a href="/" class="back-btn">← Back to Dashboard</a>
<h2>Registered Users</h2>
<div id="usersList" class="table-wrapper">
<p class="loading">Fetching secure data...</p>
</div>
</div>
<script>
async function fetchUsers() {
try {
const token = localStorage.getItem('token');
if (!token) {
window.location.href = '/login?role=Admin';
return;
}
const response = await fetch('/api/admin/users', {
headers: {
'Authorization': `Bearer ${token}`
}
});
if (!response.ok) {
if (response.status === 403 || response.status === 401) {
// For safety, immediately transfer unauthenticated users to the secure login portal
localStorage.removeItem('token');
window.location.href = '/login?role=Admin';
return;
}
throw new Error('Failed to fetch data');
}
const users = await response.json();
let html = `
<table>
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Mobile</th>
<th>Role</th>
<th>Qns Asked</th>
</tr>
</thead>
<tbody>
`;
users.forEach(user => {
const badgeClass = user.role === 'Admin' ? 'badge-Admin' : 'badge-User';
html += `
<tr>
<td>${user.id}</td>
<td>${user.username}</td>
<td>${user.email}</td>
<td>${user.mobile_number || '<span style="color:#666">N/A</span>'}</td>
<td><span class="badge ${badgeClass}">${user.role}</span></td>
<td>${user.question_count}</td>
</tr>
`;
});
html += `</tbody></table>`;
document.getElementById('usersList').innerHTML = users.length > 0 ? html : '<p style="text-align:center; padding: 2rem;">No users found.</p>';
} catch (err) {
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>`;
}
}
fetchUsers();
</script>
</body>
</html> |