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
+18 -33
View File
@@ -2,17 +2,19 @@ const visibility = [{ id: 0, name: "Public" }, { id: 1, name: "Unlisted" }, { id
document.addEventListener("DOMContentLoaded", async function () {
const id = window.location.pathname.split("/")[1];
const content = await (await fetch(`/api/pastes/${id}`)).text();
const info = await (await fetch(`/api/pastes/${id}/info`)).json();
const paste = info.paste;
const contentPromise = fetch(`/api/pastes/${id}`).then(response => response.text());
const infoPromise = fetch(`/api/pastes/${id}/info`).then(response => response.json());
const blur = document.createElement("div");
blur.id = "blur";
blur.dataset.decrypted = "false";
document.body.appendChild(blur);
const blur2 = document.getElementById("blur");
if (paste.visibility === 2) {
const [content, info] = await Promise.all([contentPromise, infoPromise]);
const paste = info.paste;
if (paste.visibility === 2) {
const password = prompt("Enter the password");
try {
const decrypted = await decryptAES(content, password);
@@ -21,53 +23,37 @@ document.addEventListener("DOMContentLoaded", async function () {
} catch (error) {
alert("Failed to decrypt, invalid password, or invalid data.");
}
} else {
blur2.dataset.decrypted = "true";
addContent(content, paste.syntax);
}
document.title = `${paste.title} - Sharpbin`;
addInfo(paste);
});
function addInfo(paste) {
document.getElementById("paste-title").innerText = paste.title;
document.getElementById("paste-date").innerText = convertUnixToLocal(paste.created);
document.getElementById("paste-syntax").innerText = paste.syntax === "none" ? "" : paste.syntax || "";
document.getElementById("info-throbber").style.display = "none";
document.getElementById("copy-button").addEventListener("click", function () {
navigator.clipboard.writeText(window.location.href);
});
document.getElementById("download-button").addEventListener("click", function () {
if (paste.visibility === 2) {
const content = document.getElementById("paste-content").innerText;
const blob = new Blob([content], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${paste.title}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
else {
const blob = new Blob([document.getElementById("paste-content").innerText], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${paste.title}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
const content = document.getElementById("paste-content").innerText;
const blob = new Blob([content], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${paste.title}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
document.getElementById("raw-button").addEventListener("click", function () {
window.location.href = `/raw/${paste.id}`;
});
}
function addContent(content, syntax) {
@@ -80,11 +66,10 @@ function addContent(content, syntax) {
code.id = "paste-content";
code.classList.add("language-" + syntax === "plaintext" ? "none" : syntax);
if (syntax !== "plaintext" && syntax !== "none" && syntax !== "" && syntax !== null) {
console.log(syntax);
hljs.highlightElement(code);
}
hljs.lineNumbersBlock(code);
document.getElementById("content-throbber").style.display = "none";
}
async function decryptAES(content, password) {