Add user authentication and dashboard features

- Implemented login and registration forms with validation.
- Created dashboard layout to display user account information and pastes.
- Added JavaScript functionality for fetching account data and pastes.
- Styled authentication and dashboard pages with CSS.
- Introduced modals for logout and account deletion confirmation.
- Included error handling for user actions and API responses.

### Copilot generated commit message
This commit is contained in:
whoswhip
2025-05-17 22:20:07 -04:00
parent 94fb936b32
commit 2a25ab1ab8
20 changed files with 2185 additions and 299 deletions
+68 -42
View File
@@ -1,50 +1,74 @@
pages = 0;
let pages = 0;
let currentPage = 0;
document.addEventListener('DOMContentLoaded', async () => {
var queries = new URLSearchParams(window.location.search);
var page = queries.get("page");
var limit = queries.get("limit");
const queries = new URLSearchParams(window.location.search);
let page = parseInt(queries.get("page"));
let limit = parseInt(queries.get("limit"));
if (parseInt(page).isNaN) {
if (isNaN(page)) {
page = 0;
}
var archiveList = document.getElementById("archives");
var archiveListHTML = "";
var pagesElement = document.getElementById("paste-pages");
if (page == null || page < 0) {
if (page < 0) {
page = 0;
}
if (limit == null || limit < 1 || limit > 25) {
if (isNaN(limit) || limit < 1 || limit > 25) {
limit = 25;
}
var archiveData = await getPastes(page, limit);
currentPage = page;
var pastes = archiveData.pastes;
pages = archiveData.pages;
pagesElement.innerText = `${parseInt(page) + 1}/${pages + 1}`;
const archiveList = document.getElementById("archives");
const pagesElement = document.getElementById("paste-pages");
const previousButton = document.getElementById("previous-button");
const nextButton = document.getElementById("next-button");
try {
archiveList.innerHTML = '<div class="loading-spinner"><div></div><div></div><div></div></div>';
const archiveData = await getPastes(page, limit);
const pastes = archiveData.pastes;
pages = archiveData.pages;
pagesElement.innerText = `${parseInt(page) + 1}/${pages}`;
previousButton.disabled = page <= 0;
nextButton.disabled = page + 1 >= pages;
if (pastes.length === 0) {
archiveList.innerHTML = '<div class="no-pastes">No pastes found</div>';
return;
}
pastes.forEach(paste => {
var title = paste.title.length > 30 ? paste.title.substring(0, 30) + '...' : paste.title;
archiveListHTML += `
<li>
<a href="/${paste.id}">
<p id="archive-title" title="${paste.title}">${title}</p>
<p id="archive-date">${formatDate(paste.created)}</p>
<p id="archive-syntax">${paste.syntax}</p>
</a>
</li>
`;
});
let archiveListHTML = "";
pastes.forEach(paste => {
const title = paste.title.length > 30 ? paste.title.substring(0, 30) + '...' : paste.title;
archiveListHTML += `
<li>
<a href="/${paste.id}">
<p id="archive-title" title="${paste.title}">${title}</p>
<p id="archive-date">${formatDate(paste.created)}</p>
<p id="archive-syntax">${paste.syntax || 'Plain Text'}</p>
</a>
</li>
`;
});
archiveList.innerHTML = archiveListHTML;
archiveList.innerHTML = archiveListHTML;
} catch (error) {
console.error('Error fetching pastes:', error);
archiveList.innerHTML = '<div class="error-message">Failed to load pastes. Please try again later.</div>';
}
});
async function getPastes(page, limit) {
const response = await fetch(`/api/pastes/archive?page=${page}&limit=${limit}`);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
}
@@ -53,8 +77,8 @@ function formatDate(unix) {
if (typeof unix !== 'number' || isNaN(unix)) {
return 'Invalid date';
}
var nowunix = Math.floor(Date.now() / 1000);
var diff = nowunix - unix;
const nowunix = Math.floor(Date.now() / 1000);
const diff = nowunix - unix;
if (diff < 60) {
return `${diff} second${diff !== 1 ? 's' : ''} ago`;
@@ -71,14 +95,15 @@ function formatDate(unix) {
}
function nextPage() {
var queries = new URLSearchParams(window.location.search);
var page = queries.get("page");
var limit = queries.get("limit");
const queries = new URLSearchParams(window.location.search);
let page = parseInt(queries.get("page"));
let limit = parseInt(queries.get("limit"));
if (page == null || page < 0) {
if (isNaN(page) || page < 0) {
page = 0;
}
if (limit == null || limit < 1 || limit > 25) {
if (isNaN(limit) || limit < 1 || limit > 25) {
limit = 25;
}
@@ -91,21 +116,22 @@ function nextPage() {
}
function previousPage() {
var queries = new URLSearchParams(window.location.search);
var page = queries.get("page");
var limit = queries.get("limit");
const queries = new URLSearchParams(window.location.search);
let page = parseInt(queries.get("page"));
let limit = parseInt(queries.get("limit"));
if (page == null || page < 0) {
if (isNaN(page) || page < 0) {
page = 0;
}
if (limit == null || limit < 1 || limit > 25) {
if (isNaN(limit) || limit < 1 || limit > 25) {
limit = 25;
}
if (page < pages) {
if (page <= 0) {
return;
}
page--;
window.location.href = `/archive?page=${page}&limit=${limit}`;
}
}