Spaces:
Running
Running
Upload 2 files
Browse files
src/apps/templates/admin_users.html
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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">
|
| 6 |
+
<title>Admin Dashboard - Users List</title>
|
| 7 |
+
<link rel="stylesheet" href="/static/css/styles.css">
|
| 8 |
+
<style>
|
| 9 |
+
.admin-container {
|
| 10 |
+
max-width: 1200px;
|
| 11 |
+
margin: 40px auto;
|
| 12 |
+
padding: 2rem;
|
| 13 |
+
background: rgba(255, 255, 255, 0.05);
|
| 14 |
+
backdrop-filter: blur(10px);
|
| 15 |
+
border-radius: 12px;
|
| 16 |
+
color: white;
|
| 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 |
+
h2 { text-align: center; margin-bottom: 2rem; font-size: 2rem; color: #9b87f5; }
|
| 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 |
+
th, td {
|
| 31 |
+
padding: 1.25rem;
|
| 32 |
+
text-align: left;
|
| 33 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
| 34 |
+
}
|
| 35 |
+
th {
|
| 36 |
+
background: rgba(155, 135, 245, 0.2);
|
| 37 |
+
color: #D6BCFA;
|
| 38 |
+
font-weight: 600;
|
| 39 |
+
text-transform: uppercase;
|
| 40 |
+
font-size: 0.85rem;
|
| 41 |
+
letter-spacing: 0.05em;
|
| 42 |
+
}
|
| 43 |
+
tr:hover { background: rgba(255, 255, 255, 0.03); }
|
| 44 |
+
.badge {
|
| 45 |
+
padding: 0.35rem 0.75rem;
|
| 46 |
+
border-radius: 9999px;
|
| 47 |
+
font-size: 0.75rem;
|
| 48 |
+
font-weight: 500;
|
| 49 |
+
}
|
| 50 |
+
.badge-Admin { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
|
| 51 |
+
.badge-User { background: rgba(59, 130, 246, 0.2); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.2); }
|
| 52 |
+
.loading { text-align: center; font-style: italic; padding: 2rem; color: #a1a1aa; }
|
| 53 |
+
.back-btn {
|
| 54 |
+
display: inline-block;
|
| 55 |
+
margin-bottom: 1rem;
|
| 56 |
+
color: #9b87f5;
|
| 57 |
+
text-decoration: none;
|
| 58 |
+
font-size: 0.9rem;
|
| 59 |
+
}
|
| 60 |
+
.back-btn:hover { text-decoration: underline; }
|
| 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>
|
| 66 |
+
<h2>Registered Users</h2>
|
| 67 |
+
<div id="usersList" class="table-wrapper">
|
| 68 |
+
<p class="loading">Fetching secure data...</p>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
<script>
|
| 73 |
+
async function fetchUsers() {
|
| 74 |
+
try {
|
| 75 |
+
const response = await fetch('/api/admin/users');
|
| 76 |
+
if (!response.ok) {
|
| 77 |
+
if (response.status === 403) throw new Error('Access denied: Admin only');
|
| 78 |
+
if (response.status === 401) throw new Error('Not logged in');
|
| 79 |
+
throw new Error('Failed to fetch data');
|
| 80 |
+
}
|
| 81 |
+
const users = await response.json();
|
| 82 |
+
|
| 83 |
+
let html = `
|
| 84 |
+
<table>
|
| 85 |
+
<thead>
|
| 86 |
+
<tr>
|
| 87 |
+
<th>ID</th>
|
| 88 |
+
<th>Username</th>
|
| 89 |
+
<th>Email</th>
|
| 90 |
+
<th>Mobile</th>
|
| 91 |
+
<th>Role</th>
|
| 92 |
+
<th>Qns Asked</th>
|
| 93 |
+
</tr>
|
| 94 |
+
</thead>
|
| 95 |
+
<tbody>
|
| 96 |
+
`;
|
| 97 |
+
|
| 98 |
+
users.forEach(user => {
|
| 99 |
+
const badgeClass = user.role === 'Admin' ? 'badge-Admin' : 'badge-User';
|
| 100 |
+
html += `
|
| 101 |
+
<tr>
|
| 102 |
+
<td>${user.id}</td>
|
| 103 |
+
<td>${user.username}</td>
|
| 104 |
+
<td>${user.email}</td>
|
| 105 |
+
<td>${user.mobile_number || '<span style="color:#666">N/A</span>'}</td>
|
| 106 |
+
<td><span class="badge ${badgeClass}">${user.role}</span></td>
|
| 107 |
+
<td>${user.question_count}</td>
|
| 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 |
+
</html>
|
src/apps/templates/register.html
CHANGED
|
@@ -83,6 +83,10 @@
|
|
| 83 |
<label for="username">Username</label>
|
| 84 |
<input type="text" id="username" required>
|
| 85 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
<div class="form-group">
|
| 87 |
<label for="email">Email</label>
|
| 88 |
<input type="email" id="email" required>
|
|
@@ -112,13 +116,20 @@
|
|
| 112 |
const username = document.getElementById('username').value;
|
| 113 |
const email = document.getElementById('email').value;
|
| 114 |
const password = document.getElementById('password').value;
|
|
|
|
| 115 |
const roleValue = document.getElementById('role').value;
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
try {
|
| 118 |
const response = await fetch('/api/register', {
|
| 119 |
method: 'POST',
|
| 120 |
headers: { 'Content-Type': 'application/json' },
|
| 121 |
-
body: JSON.stringify({ username, email, password, role: roleValue })
|
| 122 |
});
|
| 123 |
|
| 124 |
const data = await response.json();
|
|
|
|
| 83 |
<label for="username">Username</label>
|
| 84 |
<input type="text" id="username" required>
|
| 85 |
</div>
|
| 86 |
+
<div class="form-group">
|
| 87 |
+
<label for="mobile_number">Mobile Number</label>
|
| 88 |
+
<input type="tel" id="mobile_number" placeholder="10-digit number" pattern="\d{10}" maxlength="10" required>
|
| 89 |
+
</div>
|
| 90 |
<div class="form-group">
|
| 91 |
<label for="email">Email</label>
|
| 92 |
<input type="email" id="email" required>
|
|
|
|
| 116 |
const username = document.getElementById('username').value;
|
| 117 |
const email = document.getElementById('email').value;
|
| 118 |
const password = document.getElementById('password').value;
|
| 119 |
+
const mobile_number = document.getElementById('mobile_number').value;
|
| 120 |
const roleValue = document.getElementById('role').value;
|
| 121 |
|
| 122 |
+
// Simple 10-digit check before submitting
|
| 123 |
+
if (!/^\d{10}$/.test(mobile_number)) {
|
| 124 |
+
alert('Please enter a valid 10-digit mobile number.');
|
| 125 |
+
return;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
try {
|
| 129 |
const response = await fetch('/api/register', {
|
| 130 |
method: 'POST',
|
| 131 |
headers: { 'Content-Type': 'application/json' },
|
| 132 |
+
body: JSON.stringify({ username, email, password, role: roleValue, mobile_number })
|
| 133 |
});
|
| 134 |
|
| 135 |
const data = await response.json();
|