LawBot / src /apps /templates /admin_users.html
Vishwanath77's picture
Upload admin_users.html
76f689b verified
<!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>