first commit
This commit is contained in:
679
templates/admin.html
Normal file
679
templates/admin.html
Normal file
@@ -0,0 +1,679 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard - Audiobook Maker Pro</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #4f46e5;
|
||||
--primary-hover: #4338ca;
|
||||
--success-color: #10b981;
|
||||
--danger-color: #ef4444;
|
||||
--warning-color: #f59e0b;
|
||||
--bg-primary: #f8fafc;
|
||||
--text-primary: #1e293b;
|
||||
--text-secondary: #64748b;
|
||||
--text-muted: #94a3b8;
|
||||
--border-color: #e2e8f0;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
|
||||
color: white;
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.admin-header h1 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.admin-header-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.admin-header-actions .btn {
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.btn-header-light {
|
||||
background: rgba(255,255,255,0.15);
|
||||
border: 1.5px solid rgba(255,255,255,0.4);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-header-light:hover {
|
||||
background: rgba(255,255,255,0.25);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.admin-container {
|
||||
max-width: 900px;
|
||||
margin: 32px auto;
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.admin-card {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
|
||||
border: 1px solid var(--border-color);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.admin-card-header {
|
||||
padding: 20px 24px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.admin-card-header h2 {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.user-count-badge {
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
padding: 2px 10px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.user-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.user-table th {
|
||||
background: var(--bg-primary);
|
||||
padding: 12px 20px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
color: var(--text-secondary);
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.user-table td {
|
||||
padding: 14px 20px;
|
||||
border-bottom: 1px solid #f1f5f9;
|
||||
font-size: 0.88rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.user-table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.user-table tr:hover td {
|
||||
background: #fafbfd;
|
||||
}
|
||||
|
||||
.role-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 10px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.3px;
|
||||
}
|
||||
|
||||
.role-badge.admin {
|
||||
background: #ede9fe;
|
||||
color: #5b21b6;
|
||||
}
|
||||
|
||||
.role-badge.user {
|
||||
background: #e0f2fe;
|
||||
color: #0369a1;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-badge .status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.status-badge.active .status-dot { background: var(--success-color); }
|
||||
.status-badge.active { color: #065f46; }
|
||||
.status-badge.disabled .status-dot { background: var(--danger-color); }
|
||||
.status-badge.disabled { color: #991b1b; }
|
||||
|
||||
.user-actions .btn {
|
||||
padding: 4px 10px;
|
||||
font-size: 0.78rem;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.date-text {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 12px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Modal tweaks */
|
||||
.modal-content {
|
||||
border: none;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 20px 50px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding: 20px 24px;
|
||||
}
|
||||
|
||||
.modal-body { padding: 24px; }
|
||||
.modal-footer { border-top: 1px solid var(--border-color); padding: 16px 24px; }
|
||||
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.85rem;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-control, .form-select {
|
||||
padding: 10px 14px;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.form-control:focus, .form-select:focus {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
|
||||
}
|
||||
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.admin-header {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.admin-card-header {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
.user-table {
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.user-table th, .user-table td {
|
||||
padding: 10px 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
<header class="admin-header">
|
||||
<h1>
|
||||
<i class="bi bi-shield-lock"></i>
|
||||
Admin Dashboard
|
||||
</h1>
|
||||
<div class="admin-header-actions">
|
||||
<span class="text-white-50" id="currentUserLabel"></span>
|
||||
<a href="/" class="btn btn-header-light btn-sm">
|
||||
<i class="bi bi-arrow-left me-1"></i> Back to App
|
||||
</a>
|
||||
<button class="btn btn-header-light btn-sm" onclick="handleLogout()">
|
||||
<i class="bi bi-box-arrow-right me-1"></i> Logout
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="admin-container">
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-header">
|
||||
<h2>
|
||||
<i class="bi bi-people"></i>
|
||||
User Management
|
||||
<span class="user-count-badge" id="userCountBadge">0 users</span>
|
||||
</h2>
|
||||
<button class="btn btn-primary btn-sm" onclick="openCreateModal()">
|
||||
<i class="bi bi-person-plus me-1"></i> Create User
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="userTableContainer">
|
||||
<div class="empty-state">
|
||||
<div class="spinner-border text-primary" role="status"></div>
|
||||
<p class="mt-2">Loading users...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Toast Container -->
|
||||
<div class="toast-container" id="toastContainer"></div>
|
||||
|
||||
<!-- Create/Edit User Modal -->
|
||||
<div class="modal fade" id="userModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="userModalTitle">
|
||||
<i class="bi bi-person-plus me-2"></i>Create New User
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="editUserId">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="modalUsername" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="modalUsername"
|
||||
placeholder="Enter username" minlength="3" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="modalPassword" class="form-label">
|
||||
Password
|
||||
<span class="text-muted fw-normal" id="passwordHint" style="display:none;">(leave blank to keep current)</span>
|
||||
</label>
|
||||
<input type="text" class="form-control" id="modalPassword"
|
||||
placeholder="Enter password" minlength="4">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="modalRole" class="form-label">Role</label>
|
||||
<select class="form-select" id="modalRole">
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" id="activeField" style="display:none;">
|
||||
<label class="form-label">Status</label>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="modalActive" checked>
|
||||
<label class="form-check-label" for="modalActive">Account Active</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-danger" id="modalError" style="display:none;"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="modalSaveBtn" onclick="saveUser()">
|
||||
<i class="bi bi-check-lg me-1"></i> Create User
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="bi bi-exclamation-triangle text-danger me-2"></i>Delete User</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Are you sure you want to delete <strong id="deleteUserName"></strong>?</p>
|
||||
<p class="text-muted small mb-0">This action cannot be undone.</p>
|
||||
<input type="hidden" id="deleteUserId">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-danger btn-sm" onclick="confirmDelete()">
|
||||
<i class="bi bi-trash me-1"></i> Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
let userModal, deleteModal;
|
||||
let currentUsers = [];
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
userModal = new bootstrap.Modal(document.getElementById('userModal'));
|
||||
deleteModal = new bootstrap.Modal(document.getElementById('deleteModal'));
|
||||
|
||||
loadCurrentUser();
|
||||
loadUsers();
|
||||
});
|
||||
|
||||
async function loadCurrentUser() {
|
||||
try {
|
||||
const resp = await fetch('/api/auth/me');
|
||||
const data = await resp.json();
|
||||
if (data.user) {
|
||||
document.getElementById('currentUserLabel').textContent =
|
||||
`Logged in as ${data.user.username}`;
|
||||
}
|
||||
} catch(e) { /* ignore */ }
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const resp = await fetch('/api/admin/users');
|
||||
const data = await resp.json();
|
||||
currentUsers = data.users || [];
|
||||
renderUserTable(currentUsers);
|
||||
} catch(e) {
|
||||
document.getElementById('userTableContainer').innerHTML =
|
||||
'<div class="empty-state"><i class="bi bi-exclamation-circle"></i><p>Failed to load users</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
function renderUserTable(users) {
|
||||
const container = document.getElementById('userTableContainer');
|
||||
const badge = document.getElementById('userCountBadge');
|
||||
badge.textContent = `${users.length} user${users.length !== 1 ? 's' : ''}`;
|
||||
|
||||
if (users.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state"><i class="bi bi-people"></i><p>No users found</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = `<table class="user-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Role</th>
|
||||
<th>Status</th>
|
||||
<th>Last Login</th>
|
||||
<th>Created</th>
|
||||
<th style="text-align:right;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>`;
|
||||
|
||||
for (const user of users) {
|
||||
const statusClass = user.is_active ? 'active' : 'disabled';
|
||||
const statusText = user.is_active ? 'Active' : 'Disabled';
|
||||
const lastLogin = user.last_login ? formatDate(user.last_login) : '<span class="text-muted">Never</span>';
|
||||
|
||||
html += `<tr>
|
||||
<td>
|
||||
<strong>${escapeHtml(user.username)}</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span class="role-badge ${user.role}">
|
||||
<i class="bi bi-${user.role === 'admin' ? 'shield-check' : 'person'}"></i>
|
||||
${user.role}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="status-badge ${statusClass}">
|
||||
<span class="status-dot"></span>
|
||||
${statusText}
|
||||
</span>
|
||||
</td>
|
||||
<td class="date-text">${lastLogin}</td>
|
||||
<td class="date-text">${formatDate(user.created_at)}</td>
|
||||
<td style="text-align:right;">
|
||||
<div class="user-actions d-flex gap-1 justify-content-end">
|
||||
<button class="btn btn-outline-primary btn-sm" onclick="openEditModal(${user.id})" title="Edit user">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-outline-danger btn-sm" onclick="openDeleteModal(${user.id}, '${escapeHtml(user.username)}')" title="Delete user">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
html += '</tbody></table>';
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
// --- Create / Edit ---
|
||||
|
||||
function openCreateModal() {
|
||||
document.getElementById('userModalTitle').innerHTML = '<i class="bi bi-person-plus me-2"></i>Create New User';
|
||||
document.getElementById('editUserId').value = '';
|
||||
document.getElementById('modalUsername').value = '';
|
||||
document.getElementById('modalPassword').value = '';
|
||||
document.getElementById('modalPassword').required = true;
|
||||
document.getElementById('modalPassword').placeholder = 'Enter password';
|
||||
document.getElementById('passwordHint').style.display = 'none';
|
||||
document.getElementById('modalRole').value = 'user';
|
||||
document.getElementById('modalActive').checked = true;
|
||||
document.getElementById('activeField').style.display = 'none';
|
||||
document.getElementById('modalSaveBtn').innerHTML = '<i class="bi bi-check-lg me-1"></i> Create User';
|
||||
document.getElementById('modalError').style.display = 'none';
|
||||
userModal.show();
|
||||
}
|
||||
|
||||
function openEditModal(userId) {
|
||||
const user = currentUsers.find(u => u.id === userId);
|
||||
if (!user) return;
|
||||
|
||||
document.getElementById('userModalTitle').innerHTML = '<i class="bi bi-pencil me-2"></i>Edit User';
|
||||
document.getElementById('editUserId').value = userId;
|
||||
document.getElementById('modalUsername').value = user.username;
|
||||
document.getElementById('modalPassword').value = '';
|
||||
document.getElementById('modalPassword').required = false;
|
||||
document.getElementById('modalPassword').placeholder = 'Leave blank to keep current';
|
||||
document.getElementById('passwordHint').style.display = 'inline';
|
||||
document.getElementById('modalRole').value = user.role;
|
||||
document.getElementById('modalActive').checked = user.is_active;
|
||||
document.getElementById('activeField').style.display = 'block';
|
||||
document.getElementById('modalSaveBtn').innerHTML = '<i class="bi bi-check-lg me-1"></i> Save Changes';
|
||||
document.getElementById('modalError').style.display = 'none';
|
||||
userModal.show();
|
||||
}
|
||||
|
||||
async function saveUser() {
|
||||
const userId = document.getElementById('editUserId').value;
|
||||
const username = document.getElementById('modalUsername').value.trim();
|
||||
const password = document.getElementById('modalPassword').value;
|
||||
const role = document.getElementById('modalRole').value;
|
||||
const isActive = document.getElementById('modalActive').checked;
|
||||
const errorDiv = document.getElementById('modalError');
|
||||
|
||||
errorDiv.style.display = 'none';
|
||||
|
||||
if (!username || username.length < 3) {
|
||||
errorDiv.textContent = 'Username must be at least 3 characters';
|
||||
errorDiv.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!userId && (!password || password.length < 4)) {
|
||||
errorDiv.textContent = 'Password must be at least 4 characters';
|
||||
errorDiv.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
if (userId && password && password.length < 4) {
|
||||
errorDiv.textContent = 'Password must be at least 4 characters';
|
||||
errorDiv.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let url, method, body;
|
||||
|
||||
if (userId) {
|
||||
url = `/api/admin/users/${userId}`;
|
||||
method = 'PUT';
|
||||
body = { username, role, is_active: isActive };
|
||||
if (password) body.password = password;
|
||||
} else {
|
||||
url = '/api/admin/users';
|
||||
method = 'POST';
|
||||
body = { username, password, role };
|
||||
}
|
||||
|
||||
const resp = await fetch(url, {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
const data = await resp.json();
|
||||
|
||||
if (data.error) {
|
||||
errorDiv.textContent = data.error;
|
||||
errorDiv.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
userModal.hide();
|
||||
showToast(data.message || 'User saved successfully', 'success');
|
||||
loadUsers();
|
||||
|
||||
} catch(e) {
|
||||
errorDiv.textContent = 'Network error. Please try again.';
|
||||
errorDiv.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
// --- Delete ---
|
||||
|
||||
function openDeleteModal(userId, username) {
|
||||
document.getElementById('deleteUserId').value = userId;
|
||||
document.getElementById('deleteUserName').textContent = username;
|
||||
deleteModal.show();
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
const userId = document.getElementById('deleteUserId').value;
|
||||
|
||||
try {
|
||||
const resp = await fetch(`/api/admin/users/${userId}`, { method: 'DELETE' });
|
||||
const data = await resp.json();
|
||||
|
||||
deleteModal.hide();
|
||||
|
||||
if (data.error) {
|
||||
showToast(data.error, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
showToast(data.message || 'User deleted', 'success');
|
||||
loadUsers();
|
||||
|
||||
} catch(e) {
|
||||
deleteModal.hide();
|
||||
showToast('Failed to delete user', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// --- Logout ---
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
} catch(e) { /* ignore */ }
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
// --- Utilities ---
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function formatDate(dateStr) {
|
||||
if (!dateStr) return '';
|
||||
const d = new Date(dateStr);
|
||||
return d.toLocaleDateString() + ' ' + d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
function showToast(message, type = 'info') {
|
||||
const container = document.getElementById('toastContainer');
|
||||
const colors = { success: 'success', error: 'danger', info: 'primary' };
|
||||
const icons = { success: 'check-circle', error: 'exclamation-circle', info: 'info-circle' };
|
||||
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `alert alert-${colors[type] || 'info'} d-flex align-items-center gap-2`;
|
||||
toast.style.cssText = 'min-width:280px; animation: slideIn 0.3s ease; margin-bottom: 8px;';
|
||||
toast.innerHTML = `<i class="bi bi-${icons[type] || 'info-circle'}"></i> ${escapeHtml(message)}`;
|
||||
container.appendChild(toast);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.style.animation = 'slideOut 0.3s ease';
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Inject animation styles
|
||||
const s = document.createElement('style');
|
||||
s.textContent = `
|
||||
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
|
||||
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }
|
||||
`;
|
||||
document.head.appendChild(s);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
481
templates/index.html
Normal file
481
templates/index.html
Normal file
@@ -0,0 +1,481 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Audiobook Maker Pro v4</title>
|
||||
|
||||
|
||||
<!-- Bootstrap 5 -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
|
||||
<!-- Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Merriweather:ital,wght@0,400;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<link rel="stylesheet" href="/static/css/markdown-editor.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Loading Overlay -->
|
||||
<div class="loading-overlay" id="loadingOverlay">
|
||||
<div class="loading-content">
|
||||
<div class="spinner-border text-primary" role="status"></div>
|
||||
<h5 id="loadingText">Processing...</h5>
|
||||
<p id="loadingSubtext" class="text-muted">Please wait</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Welcome Overlay (first-time guide) -->
|
||||
<div class="welcome-overlay" id="welcomeOverlay">
|
||||
<div class="welcome-card">
|
||||
<div class="welcome-header">
|
||||
<i class="bi bi-soundwave"></i>
|
||||
<h2>Welcome to Audiobook Maker Pro</h2>
|
||||
<p>Turn any document into an interactive audiobook in 3 simple steps</p>
|
||||
</div>
|
||||
<div class="welcome-steps">
|
||||
<!-- Step 1 -->
|
||||
<div class="welcome-step">
|
||||
<div class="welcome-step-number">Step-1</div>
|
||||
<div class="welcome-step-icon"><i class="bi bi-upload"></i></div>
|
||||
<h4>Upload Document</h4>
|
||||
<div class="welcome-step-details">
|
||||
<p>Drag & drop a <strong>PDF</strong>, <strong>DOCX</strong>, or <strong>DOC</strong> file into the upload area</p>
|
||||
<div class="welcome-step-alt">
|
||||
<span class="welcome-alt-label">or</span>
|
||||
<p>Click <span class="welcome-ui-btn"><i class="bi bi-pencil"></i> Start from scratch</span> to write your own content</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="welcome-step-arrow"><i class="bi bi-arrow-right"></i></div>
|
||||
|
||||
<!-- Step 2 -->
|
||||
<div class="welcome-step">
|
||||
<div class="welcome-step-number">Step-2</div>
|
||||
<div class="welcome-step-icon"><i class="bi bi-soundwave"></i></div>
|
||||
<h4>Edit & Generate Audio</h4>
|
||||
<div class="welcome-step-details">
|
||||
<p>Hover between blocks and click <span class="welcome-ui-dot chapter-dot"><i class="bi bi-bookmark-star"></i></span> to add chapter markers for multi-chapter books</p>
|
||||
<p>Select a <strong>voice</strong> from the chapter dropdown, then click <span class="welcome-ui-btn success-btn"><i class="bi bi-play-fill"></i> Generate All</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="welcome-step-arrow"><i class="bi bi-arrow-right"></i></div>
|
||||
|
||||
<!-- Step 3 -->
|
||||
<div class="welcome-step">
|
||||
<div class="welcome-step-number">Step-3</div>
|
||||
<div class="welcome-step-icon"><i class="bi bi-book"></i></div>
|
||||
<h4>Read & Export</h4>
|
||||
<div class="welcome-step-details">
|
||||
<p>Switch to the <span class="welcome-ui-btn"><i class="bi bi-book"></i> Interactive Reader</span> tab to listen with word-by-word highlighting</p>
|
||||
<p>Click <span class="welcome-ui-btn primary-btn"><i class="bi bi-download"></i> Export</span> in the header to download your audiobook as a ZIP</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="welcome-actions">
|
||||
<button class="btn btn-primary btn-lg" onclick="dismissWelcome()">
|
||||
<i class="bi bi-rocket-takeoff me-2"></i>Get Started
|
||||
</button>
|
||||
<label class="welcome-dismiss-label">
|
||||
<input type="checkbox" id="welcomeDontShow"> Don't show this again
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================================================
|
||||
FLOATING GUIDE PANEL (Draggable)
|
||||
================================================= -->
|
||||
<div class="floating-guide-panel" id="floatingGuidePanel">
|
||||
<!-- Drag Handle / Header -->
|
||||
<div class="guide-panel-header" id="guidePanelHeader">
|
||||
<div class="guide-panel-title">
|
||||
<i class="bi bi-lightbulb"></i>
|
||||
<span>Quick Guide</span>
|
||||
</div>
|
||||
<div class="guide-panel-controls">
|
||||
<button class="guide-panel-btn" id="guidePanelCollapse" onclick="toggleGuideCollapse()" title="Collapse / Expand">
|
||||
<i class="bi bi-chevron-up" id="guideCollapseIcon"></i>
|
||||
</button>
|
||||
<button class="guide-panel-btn" onclick="hideGuidePanel()" title="Hide guide panel">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Panel Body -->
|
||||
<div class="guide-panel-body" id="guidePanelBody">
|
||||
<!-- Step 2: Edit & Generate -->
|
||||
<div class="guide-section">
|
||||
<div class="guide-section-badge">Step 2 — Edit & Generate</div>
|
||||
|
||||
<div class="guide-instruction">
|
||||
<span class="guide-step-num">1</span>
|
||||
<div class="guide-instruction-text">
|
||||
Hover between blocks and click
|
||||
<span class="guide-ui chapter-marker-ui" title="Add chapter marker"><i class="bi bi-bookmark-star-fill"></i></span>
|
||||
to add <strong>chapter markers</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="guide-instruction">
|
||||
<span class="guide-step-num">2</span>
|
||||
<div class="guide-instruction-text">
|
||||
Select a <strong>voice</strong> from the chapter dropdown
|
||||
<span class="guide-ui voice-dropdown-ui">
|
||||
<i class="bi bi-mic-fill"></i> Voice <i class="bi bi-chevron-down" style="font-size:0.55rem;"></i>
|
||||
</span>,
|
||||
then click
|
||||
<span class="guide-ui generate-btn-ui"><i class="bi bi-play-fill"></i> Generate All</span>
|
||||
to create audio
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="guide-instruction">
|
||||
<span class="guide-step-num">3</span>
|
||||
<div class="guide-instruction-text">
|
||||
Click
|
||||
<span class="guide-ui image-btn-ui"><i class="bi bi-image"></i></span>
|
||||
between blocks to <strong>add an image</strong> (optional)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="guide-instruction">
|
||||
<span class="guide-step-num">4</span>
|
||||
<div class="guide-instruction-text">
|
||||
Click
|
||||
<span class="guide-ui add-block-btn-ui"><i class="bi bi-plus"></i></span>
|
||||
between blocks to <strong>add a new text block</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 3: Read & Export -->
|
||||
<div class="guide-section">
|
||||
<div class="guide-section-badge step3-badge">Step 3 — Read & Export</div>
|
||||
|
||||
<div class="guide-instruction">
|
||||
<span class="guide-step-num">5</span>
|
||||
<div class="guide-instruction-text">
|
||||
Switch to the
|
||||
<span class="guide-ui reader-tab-ui"><i class="bi bi-book"></i> Interactive Reader</span>
|
||||
tab to <strong>listen</strong> with word-by-word highlighting
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="guide-instruction">
|
||||
<span class="guide-step-num">6</span>
|
||||
<div class="guide-instruction-text">
|
||||
Click
|
||||
<span class="guide-ui export-btn-ui"><i class="bi bi-download"></i> Export</span>
|
||||
in the header to <strong>download</strong> your audiobook as a ZIP
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Don't show option -->
|
||||
<div class="guide-panel-footer">
|
||||
<label class="guide-dont-show">
|
||||
<input type="checkbox" id="guidePanelDontShow" onchange="handleGuideDontShow()">
|
||||
Don't show this again
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Floating Guide Toggle Button (when panel is hidden) -->
|
||||
<button class="floating-guide-toggle" id="floatingGuideToggle" onclick="showGuidePanel()" title="Show Quick Guide">
|
||||
<i class="bi bi-lightbulb"></i>
|
||||
</button>
|
||||
|
||||
|
||||
<!-- Main Container -->
|
||||
<div class="app-container">
|
||||
<!-- Header -->
|
||||
<header class="app-header">
|
||||
<div class="header-left">
|
||||
<h1 class="app-title">
|
||||
<i class="bi bi-soundwave"></i>
|
||||
Audiobook Maker Pro
|
||||
<span class="version-badge">v4.0</span>
|
||||
</h1>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<div class="project-controls">
|
||||
<input type="text" id="projectName" class="form-control project-name-input"
|
||||
placeholder="Project Name" value="My Audiobook">
|
||||
<button class="btn btn-success" id="saveProjectBtn" onclick="saveProject()" title="Save project (Ctrl+S)">
|
||||
<i class="bi bi-save me-1"></i> Save
|
||||
</button>
|
||||
<button class="btn btn-primary" onclick="exportProject()" title="Export as ZIP with audio + reader">
|
||||
<i class="bi bi-download me-1"></i> Export
|
||||
</button>
|
||||
<button class="btn btn-header-archive" onclick="openProjectArchive()" title="Load or manage saved projects">
|
||||
<i class="bi bi-archive me-1"></i> Archive
|
||||
</button>
|
||||
<button class="btn btn-header-help" id="headerHelpBtn" onclick="handleHeaderHelp()" title="Show quick start guide">
|
||||
<i class="bi bi-question-circle me-1"></i>
|
||||
<span id="headerHelpLabel">Quick Start</span>
|
||||
</button>
|
||||
|
||||
<!-- User Menu -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-header-user dropdown-toggle" type="button"
|
||||
data-bs-toggle="dropdown" aria-expanded="false" id="userMenuBtn">
|
||||
<i class="bi bi-person-circle me-1"></i>
|
||||
<span id="headerUsername">User</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li id="adminMenuItem" style="display:none;">
|
||||
<a class="dropdown-item" href="/admin">
|
||||
<i class="bi bi-shield-lock me-2"></i>Admin Dashboard
|
||||
</a>
|
||||
</li>
|
||||
<li id="adminDivider" style="display:none;"><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="#" onclick="openChangePassword()">
|
||||
<i class="bi bi-key me-2"></i>Change Password
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item text-danger" href="#" onclick="handleLogout()">
|
||||
<i class="bi bi-box-arrow-right me-2"></i>Logout
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</header>
|
||||
|
||||
<!-- Workflow Progress Bar -->
|
||||
<div class="workflow-progress" id="workflowProgress">
|
||||
<div class="workflow-step active" id="wpStep1">
|
||||
<div class="workflow-step-dot">1</div>
|
||||
<span>Upload</span>
|
||||
</div>
|
||||
<div class="workflow-connector" id="wpConn1"></div>
|
||||
<div class="workflow-step" id="wpStep2">
|
||||
<div class="workflow-step-dot">2</div>
|
||||
<span>Edit & Generate</span>
|
||||
</div>
|
||||
<div class="workflow-connector" id="wpConn2"></div>
|
||||
<div class="workflow-step" id="wpStep3">
|
||||
<div class="workflow-step-dot">3</div>
|
||||
<span>Read & Export</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content Area -->
|
||||
<main class="main-content">
|
||||
<!-- Tab Navigation -->
|
||||
<ul class="nav nav-tabs main-tabs" id="mainTabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<button class="nav-link active" id="editor-tab" data-bs-toggle="tab"
|
||||
data-bs-target="#editorPanel" type="button">
|
||||
<i class="bi bi-pencil-square me-1"></i> Audiobook Maker Editor
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" id="reader-tab" data-bs-toggle="tab"
|
||||
data-bs-target="#readerPanel" type="button">
|
||||
<i class="bi bi-book me-1"></i> Interactive Reader
|
||||
<span class="reader-tab-badge" id="readerTabBadge" style="display:none;">
|
||||
Ready
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab Content -->
|
||||
<div class="tab-content" id="mainTabContent">
|
||||
<!-- Editor Panel -->
|
||||
<div class="tab-pane fade show active" id="editorPanel" role="tabpanel">
|
||||
|
||||
<!-- Upload Section: Two-Pathway Layout -->
|
||||
<div class="upload-section" id="uploadSection">
|
||||
<div class="upload-zone-wrapper">
|
||||
|
||||
<!-- Option A: Upload a Document -->
|
||||
<div class="upload-zone" id="uploadZone">
|
||||
<input type="file" id="docInput" accept=".pdf,.doc,.docx" hidden>
|
||||
<div class="upload-content">
|
||||
<i class="bi bi-file-earmark-arrow-up upload-icon"></i>
|
||||
<h4>Upload Document</h4>
|
||||
<p class="text-muted mb-3">
|
||||
Drag & drop a file here, or click the button below to browse
|
||||
</p>
|
||||
<div class="d-flex gap-2 justify-content-center flex-wrap mb-3">
|
||||
<span class="badge bg-danger bg-opacity-10 text-danger px-3 py-2">
|
||||
<i class="bi bi-file-earmark-pdf me-1"></i>PDF
|
||||
</span>
|
||||
<span class="badge bg-primary bg-opacity-10 text-primary px-3 py-2">
|
||||
<i class="bi bi-file-earmark-word me-1"></i>DOCX
|
||||
</span>
|
||||
<span class="badge bg-info bg-opacity-10 text-info px-3 py-2">
|
||||
<i class="bi bi-file-earmark-word me-1"></i>DOC
|
||||
</span>
|
||||
</div>
|
||||
<button class="btn btn-primary btn-lg" onclick="event.stopPropagation(); document.getElementById('docInput').click()">
|
||||
<i class="bi bi-upload me-2"></i>Choose File
|
||||
</button>
|
||||
<p class="upload-hint-text">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Your document will be split into editable blocks automatically
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Vertical "or" Divider -->
|
||||
<div class="pathway-divider">
|
||||
<span>or</span>
|
||||
</div>
|
||||
|
||||
<!-- Option B: Start from Scratch -->
|
||||
<div class="scratch-zone" id="scratchZone" onclick="startFromScratch()">
|
||||
<div class="scratch-content">
|
||||
<i class="bi bi-pencil-square scratch-icon"></i>
|
||||
<h4>Start from Scratch</h4>
|
||||
<p class="text-muted mb-3">
|
||||
Write or paste your own content directly into the editor
|
||||
</p>
|
||||
<button class="btn btn-outline-primary btn-lg" onclick="event.stopPropagation(); startFromScratch()">
|
||||
<i class="bi bi-pencil me-2"></i>Start Writing
|
||||
</button>
|
||||
<p class="upload-hint-text">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Add chapters, format text, and insert images manually
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Editor Section: Hidden by default -->
|
||||
<div class="editor-section" id="editorSection" style="display:none">
|
||||
<div class="editor-container" id="markdownEditor">
|
||||
<div class="empty-editor-message" id="emptyEditorMessage">
|
||||
<i class="bi bi-file-text"></i>
|
||||
<p>Upload a document or start typing to create content</p>
|
||||
<p class="text-muted small">Click anywhere to add a new block</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reader Panel -->
|
||||
<div class="tab-pane fade" id="readerPanel" role="tabpanel">
|
||||
<div class="reader-container" id="readerContainer">
|
||||
<div class="reader-empty-state">
|
||||
<i class="bi bi-book"></i>
|
||||
<p>Generate audio to view the interactive reader</p>
|
||||
<p class="text-muted">Go to the Editor tab, then click <strong>"Generate All"</strong> on a chapter</p>
|
||||
<button class="btn btn-primary mt-3" onclick="switchToEditorTab()">
|
||||
<i class="bi bi-arrow-left me-1"></i> Go to Editor
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- Project Archive Modal -->
|
||||
<div class="modal fade" id="archiveModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="bi bi-archive me-2"></i>Project Archive
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="projectList"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- TTS Edit Modal -->
|
||||
<div class="modal fade" id="ttsEditModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="bi bi-mic me-2"></i>Edit Text for TTS Generation
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="text-muted small mb-2">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
This text will be used for audio generation. The original markdown content will be preserved.
|
||||
</p>
|
||||
<textarea id="ttsTextInput" class="form-control" rows="8"></textarea>
|
||||
<input type="hidden" id="ttsBlockId">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" onclick="saveTtsText()">
|
||||
<i class="bi bi-check-lg me-1"></i>Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Change Password Modal -->
|
||||
<div class="modal fade" id="changePasswordModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="bi bi-key me-2"></i>Change Password
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="currentPassword" class="form-label">Current Password</label>
|
||||
<input type="password" class="form-control" id="currentPassword" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="newPassword" class="form-label">New Password</label>
|
||||
<input type="password" class="form-control" id="newPassword" required minlength="4">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="confirmPassword" class="form-label">Confirm New Password</label>
|
||||
<input type="password" class="form-control" id="confirmPassword" required>
|
||||
</div>
|
||||
<div class="alert alert-danger" id="changePasswordError" style="display:none;"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" onclick="submitChangePassword()">
|
||||
<i class="bi bi-check-lg me-1"></i>Change Password
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Scripts -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<script src="/static/js/app.js"></script>
|
||||
<script src="/static/js/markdown-editor.js"></script>
|
||||
<script src="/static/js/pdf-handler.js"></script>
|
||||
<script src="/static/js/generation.js"></script>
|
||||
<script src="/static/js/interactive-reader.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
345
templates/login.html
Normal file
345
templates/login.html
Normal file
@@ -0,0 +1,345 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Audiobook Maker Pro</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #4f46e5;
|
||||
--primary-hover: #4338ca;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 48px 40px;
|
||||
box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
|
||||
animation: slideUp 0.4s ease;
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from { opacity: 0; transform: translateY(20px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 36px;
|
||||
}
|
||||
|
||||
.login-logo {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border-radius: 16px;
|
||||
background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 16px;
|
||||
font-size: 1.75rem;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
color: #64748b;
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 10px;
|
||||
font-size: 0.95rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
|
||||
}
|
||||
|
||||
.input-group-text {
|
||||
background: #f8fafc;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-right: none;
|
||||
border-radius: 10px 0 0 10px;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.input-group .form-control {
|
||||
border-left: none;
|
||||
border-radius: 0 10px 10px 0;
|
||||
}
|
||||
|
||||
.input-group:focus-within .input-group-text {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.btn-login {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-login:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 8px 25px rgba(79, 70, 229, 0.4);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-login:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.btn-login:disabled {
|
||||
opacity: 0.7;
|
||||
transform: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.login-error {
|
||||
background: #fef2f2;
|
||||
border: 1px solid #fecaca;
|
||||
color: #dc2626;
|
||||
border-radius: 10px;
|
||||
padding: 12px 16px;
|
||||
font-size: 0.85rem;
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 20px;
|
||||
animation: shakeError 0.4s ease;
|
||||
}
|
||||
|
||||
.login-error.visible {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@keyframes shakeError {
|
||||
0%, 100% { transform: translateX(0); }
|
||||
25% { transform: translateX(-8px); }
|
||||
75% { transform: translateX(8px); }
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 24px;
|
||||
color: #94a3b8;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.password-toggle {
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: none;
|
||||
border: none;
|
||||
color: #94a3b8;
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.password-toggle:hover {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.password-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.password-wrapper .form-control {
|
||||
padding-right: 44px;
|
||||
}
|
||||
|
||||
.spinner-border-sm {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="login-card">
|
||||
<div class="login-header">
|
||||
<div class="login-logo">
|
||||
<i class="bi bi-soundwave"></i>
|
||||
</div>
|
||||
<h1>Audiobook Maker Pro</h1>
|
||||
<p>Sign in to your account</p>
|
||||
</div>
|
||||
|
||||
<div class="login-error" id="loginError">
|
||||
<i class="bi bi-exclamation-triangle-fill"></i>
|
||||
<span id="loginErrorText"></span>
|
||||
</div>
|
||||
|
||||
<form id="loginForm" onsubmit="handleLogin(event)">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="bi bi-person"></i></span>
|
||||
<input type="text" class="form-control" id="username"
|
||||
placeholder="Enter your username" required autofocus
|
||||
autocomplete="username">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="bi bi-lock"></i></span>
|
||||
<div class="password-wrapper" style="flex:1;">
|
||||
<input type="password" class="form-control" id="password"
|
||||
placeholder="Enter your password" required
|
||||
autocomplete="current-password">
|
||||
<button type="button" class="password-toggle" onclick="togglePassword()">
|
||||
<i class="bi bi-eye" id="passwordToggleIcon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-login" id="loginBtn">
|
||||
<span id="loginBtnText">Sign In</span>
|
||||
<div class="spinner-border spinner-border-sm" id="loginSpinner" style="display:none;" role="status"></div>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="login-footer">
|
||||
<i class="bi bi-shield-lock me-1"></i>
|
||||
Audiobook Maker Pro v3.1
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function togglePassword() {
|
||||
const input = document.getElementById('password');
|
||||
const icon = document.getElementById('passwordToggleIcon');
|
||||
|
||||
if (input.type === 'password') {
|
||||
input.type = 'text';
|
||||
icon.classList.remove('bi-eye');
|
||||
icon.classList.add('bi-eye-slash');
|
||||
} else {
|
||||
input.type = 'password';
|
||||
icon.classList.remove('bi-eye-slash');
|
||||
icon.classList.add('bi-eye');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogin(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const errorDiv = document.getElementById('loginError');
|
||||
const errorText = document.getElementById('loginErrorText');
|
||||
const loginBtn = document.getElementById('loginBtn');
|
||||
const btnText = document.getElementById('loginBtnText');
|
||||
const spinner = document.getElementById('loginSpinner');
|
||||
|
||||
// Hide previous error
|
||||
errorDiv.classList.remove('visible');
|
||||
|
||||
// Show loading
|
||||
loginBtn.disabled = true;
|
||||
btnText.textContent = 'Signing in...';
|
||||
spinner.style.display = 'inline-block';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.error) {
|
||||
errorText.textContent = data.error;
|
||||
errorDiv.classList.add('visible');
|
||||
loginBtn.disabled = false;
|
||||
btnText.textContent = 'Sign In';
|
||||
spinner.style.display = 'none';
|
||||
|
||||
// Shake the password field
|
||||
document.getElementById('password').select();
|
||||
return;
|
||||
}
|
||||
|
||||
// Success — redirect
|
||||
btnText.textContent = 'Redirecting...';
|
||||
window.location.href = '/';
|
||||
|
||||
} catch (error) {
|
||||
errorText.textContent = 'Network error. Please try again.';
|
||||
errorDiv.classList.add('visible');
|
||||
loginBtn.disabled = false;
|
||||
btnText.textContent = 'Sign In';
|
||||
spinner.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Enter key
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
document.getElementById('loginForm').requestSubmit();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user