Enhance validation, logging, and UI/UX improvements

## COMMIT MESSAGE GENERATED BY COPILOT

Added JSON validation to multiple endpoints, ensuring valid JSON requests and improved error handling. Updated logging to use `DateTime.Now` and append to `logs.log` for specific actions. Enhanced `/api/accounts/login` with JSON validation and refactored for consistency.  Improved admin and user interfaces with search functionality, better date localization, and CSS adjustments. Enhanced error handling and feedback in `login.html` and `signup.html`, and improved search functionality in `archives.html`.
This commit is contained in:
whoswhip
2024-09-07 13:59:33 -04:00
parent 0e2aa78b5c
commit f02e68b1d3
10 changed files with 660 additions and 395 deletions
+192 -145
View File
@@ -1,11 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
<title>create paste</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
@@ -13,7 +15,7 @@
<a href="/archive">archive</a>
{html}
</div>
<div class="container-wrapper">
<div class="container-wrapper">
<div class="dash-container">
<div class="wrapper">
<div class="idek-wrapper">
@@ -37,6 +39,7 @@
<div class="idek-wrapper">
<div class="accounts-wrapper">
<h3>Accounts</h3>
<input type="text" placeholder="search" class="text-input" oninput="search()">
<div class="list-container">
{accounts}
</div>
@@ -53,160 +56,204 @@
return date.toLocaleString();
}
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function () {
const creationdateElement = document.getElementById('creationdate');
const lastlogindateElement = document.getElementById('lastlogindate');
const creationdateText = creationdateElement.innerText.trim();
const lastlogindateText = lastlogindateElement.innerText.trim();
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
lastlogindateElement.innerText = "Last Login Date: " + localizeDateTime(parseInt(lastlogindateText));
});
function search() {
const input = document.querySelector('.text-input').value;
const accountWrapper = document.querySelector('.accounts-wrapper');
const accounts = accountWrapper.querySelectorAll('.list-a');
accounts.forEach(account => {
const username = account.querySelector('.list-item').innerText;
if (username.toLowerCase().includes(input.toLowerCase())) {
account.style.display = 'flex';
} else {
account.style.display = 'none';
}
});
}
</script>
<style>
.list-container {
max-height: 100%;
overflow-y: auto;
display: flex;
flex-direction: column;
width: 100%;
align-items: center;
}
.list-container{
max-height: 100%;
overflow-y: auto;
display: flex;
flex-direction: column;
width: 100%;
align-items: center;
justify-content: center;
}
body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #0d0d0d;
}
body{
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #0d0d0d;
}
.container-wrapper{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 98.7vh;
}
.dash-container {
display: flex;
padding: 20px;
background-color: #181818;
color: white;
border-radius: 5px;
width: 80%;
max-height: 80vh;
min-height: 20%;
height: fit-content;
border: #222222 2px solid;
}
.idek-wrapper{
display: flex;
flex-direction: row;
width: 100%;
}
.account-info{
display: flex;
flex-direction: column;
background-color: #222222;
width: 48%;
padding: 20px;
margin-right: 5px;
border-radius: 5px;
overflow-x: hidden;
overflow-y: auto;
}
.pastes-wrapper{
display: flex;
flex-direction: column;
align-items: center;
width: 48%;
margin-left: 5px;
border-radius: 5px;
padding: 20px;
overflow-x: hidden;
overflow-y: auto;
background-color: #222222;
max-height: 70vh;
}
.accounts-wrapper{
margin-top: 10px;
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
border-radius: 5px;
padding: 20px;
overflow-x: hidden;
overflow-y: auto;
background-color: #222222;
max-height: 70vh;
}
.wrapper{
display: flex;
flex-direction: column;
width: 100%;
}
.list-a{
transition: 300ms;
text-decoration: none;
color: white;
width: 90%;
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
border-radius: 5px;
background-color: #2a2a2a;
margin-top: 5px;
margin-bottom: 5px;
border: #3a3a3a00 2px solid;
}
.list-a:hover{
transition: background-color 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
.list-item{
list-style: none;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
.container-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 98.7vh;
}
.dash-container {
display: flex;
padding: 20px;
background-color: #181818;
color: white;
border-radius: 5px;
width: 80%;
max-height: 80vh;
min-height: 20%;
height: fit-content;
border: #222222 2px solid;
}
.idek-wrapper {
display: flex;
flex-direction: row;
width: 100%;
}
.account-info {
display: flex;
flex-direction: column;
background-color: #222222;
width: 48%;
padding: 20px;
margin-right: 5px;
border-radius: 5px;
overflow-x: hidden;
overflow-y: auto;
}
.pastes-wrapper {
display: flex;
flex-direction: column;
align-items: center;
width: 48%;
margin-left: 5px;
border-radius: 5px;
padding: 20px;
overflow-x: hidden;
overflow-y: auto;
background-color: #222222;
max-height: 70vh;
}
.accounts-wrapper {
margin-top: 10px;
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
border-radius: 5px;
padding: 20px;
overflow-x: hidden;
overflow-y: auto;
background-color: #222222;
max-height: 40vh;
}
.wrapper {
display: flex;
flex-direction: column;
width: 100%;
}
.list-a {
transition: 300ms;
text-decoration: none;
color: white;
width: 90%;
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
border-radius: 5px;
background-color: #2a2a2a;
margin-top: 5px;
margin-bottom: 5px;
border: #3a3a3a00 2px solid;
}
.list-a:hover {
transition: background-color 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
.list-item {
list-style: none;
}
.text-input {
transition: border 300ms;
width: 90.2%;
height: 1.2rem;
padding: 10px;
margin: 10px;
border-radius: 5px;
border: #2a2a2a 2px solid;
background-color: #2a2a2a;
color: white;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
}
.text-input:focus {
transition: border 300ms;
outline: none;
border: #333333 2px solid;
}
.nav-div {
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a {
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover {
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
</style>
</html>
+1 -1
View File
@@ -139,7 +139,7 @@
border-radius: 5px;
padding: 20px;
height: fit-content;
margin-top: 20px;
margin-top: 26px;
height: 77.1%;
max-height: 77.1%;
}
+60 -36
View File
@@ -32,54 +32,59 @@
</body>
<script>
let searchTimeout;
function search() {
function search() {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(searchPastes, 200);
}
function searchPastes() {
}
function searchPastes() {
const searchInput = document.querySelector('.text-input');
if (searchInput.value.length < 3) return;
if (searchInput.value.length < 3 && searchInput.value.length != 0){
return;
}
else if (searchInput.value.length == 0) {
fetch(`/api/pastes/search?html=true`,{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: ''
})
})
.then(response => response.text())
.then(data => {
const pastesWrapper = document.querySelector('.pastes-wrapper');
if (data === '') {
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
return;
}
pastesWrapper.innerHTML = data;
});
return;
}
fetch(`/api/pastes/search?html=true`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: searchInput.value
query: searchInput.value
})
})
.then(response => response.text())
.then(data => {
const pastesWrapper = document.querySelector('.pastes-wrapper');
if (data === '') {
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
return;
}
pastesWrapper.innerHTML = data;
});
}
.then(response => response.text())
.then(data => {
const pastesWrapper = document.querySelector('.pastes-wrapper');
if (data === '') {
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
return;
}
pastesWrapper.innerHTML = data;
});
}
</script>
<style>
.text-input {
transition: border 300ms;
width: 90.62%;
height: 1.2rem;
padding: 10px;
margin: 10px;
border-radius: 5px;
border: #222222 2px solid;
background-color: #222222;
color: white;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
}
.text-input:focus {
transition: border 300ms;
outline: none;
border: #3a3a3a 2px solid;
}
body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
@@ -187,6 +192,25 @@
border: 2px solid #3a3a3a;
}
.text-input {
transition: border 300ms;
width: 90.62%;
height: 1.2rem;
padding: 10px;
margin: 10px;
border-radius: 5px;
border: #222222 2px solid;
background-color: #222222;
color: white;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
}
.text-input:focus {
transition: border 300ms;
outline: none;
border: #3a3a3a 2px solid;
}
.nav-div {
top: 0;
margin-top: 10px;
+3
View File
@@ -71,6 +71,9 @@ body{
width: 100%;
height: 98.7vh;
}
#pasteContent {
max-height: 500px;
}
.creation-container{
display: flex;
flex-direction: column;
+24
View File
@@ -23,6 +23,7 @@
<input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50">
<button type="submit" class="button">Login</button>
</form>
<h3 id="error-message"></h3>
</div>
</div>
</body>
@@ -50,10 +51,20 @@
if (result.message != null) {
window.location.href = "/";
}
else if (result.error != null) {
const errorElement = document.getElementById("error-message");
errorElement.innerText = result.error;
errorElement.style.opacity = 1;
setTimeout(() => {
errorElement.style.opacity = 0;
}, 3000);
}
})
});
</script>
<style>
body{
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
@@ -85,6 +96,7 @@ body{
min-height: 20%;
overflow-y: auto;
border: #222222 2px solid;
position: relative;
}
#loginForm{
display: flex;
@@ -92,6 +104,16 @@ body{
align-items: center;
width: 100%;
}
#error-message{
color: red;
opacity: 0;
position: absolute;
bottom: -0.1px;
margin-bottom: -0.1px;
top: 88%;
transition: 300ms;
}
.label{
font-size: 1.5em;
}
@@ -152,6 +174,8 @@ body{
border: #2a2a2a00 2px solid;
cursor: pointer;
font-size: 1.2em;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
}
.button:hover{
transition: 300ms;
+193 -154
View File
@@ -1,11 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
<title>create paste</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
@@ -13,18 +15,19 @@
<a href="/archive">archive</a>
{html}
</div>
<div class="container-wrapper">
<div class="container-wrapper">
<div class="creation-container">
<h1>sign-up</h1>
<form id="signupForm">
<label for="usernameTitle" class="label" onforminput="">Username</label>
<input type="text" id="usernameInput" class="textinput" name="pasteTitle" required maxlength="20">
<input type="text" id="usernameInput" class="textinput" name="pasteTitle" required maxlength="20" minlength="3">
<label id="characterCount" for="characterCount" class="ccounter">0/20</label>
<label for="passwordTitle" class="label" id="margin-top">Password</label>
<input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50">
<input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50" minlength="8">
<label id="passcharacterCount" for="characterCount" class="ccounter">0/20</label>
<button type="submit" class="button" id="button-margin-top">Sign-up</button>
</form>
<h3 id="error-message"></h3>
</div>
</div>
</body>
@@ -52,6 +55,15 @@
if (result.message != null) {
window.location.href = "/";
}
else if (result.error != null) {
const errorElement = document.getElementById("error-message");
errorElement.innerText = result.error;
errorElement.style.opacity = 1;
setTimeout(() => {
errorElement.style.opacity = 0;
}, 3000);
}
})
});
document.getElementById("usernameInput").addEventListener("input", function (event) {
@@ -66,156 +78,183 @@
});
</script>
<style>
body{
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #0d0d0d;
}
.container-wrapper{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 98.7vh;
}
.creation-container{
display: flex;
flex-direction: column;
align-items: center;
width: 80%;
padding: 20px;
background-color: #181818;
color: white;
border-radius: 5px;
height: fit-content;
max-height: 80vh;
min-height: 20%;
overflow-y: auto;
border: #222222 2px solid;
}
#signupForm{
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.label{
font-size: 1.5em;
}
.textinput{
transition: 300ms;
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
background-color: #282828;
color: white;
border: #2a2a2a 2px solid;
box-sizing: border-box;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-size: 1.1em;
outline: none;
}
.textinput:focus{
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
outline: none;
}
.textarea{
transition: 300ms;
width: 100%;
min-width: 100%;
max-width: 100%;
min-height: auto;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
background-color: #282828;
color: white;
border: #2a2a2a 2px solid;
box-sizing: border-box;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-size: 1.08em;
outline: none;
}
.textarea:focus{
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
outline: none;
}
.button{
transition: 300ms;
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
background-color: #222222;
color: white;
border: #2a2a2a00 2px solid;
cursor: pointer;
font-size: 1.2em;
}
.button:hover{
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
.ccounter{
align-self: flex-end;
text-align: right;
margin-top: -2.2rem;
margin-right: 10px;
font-size: 1.1em;
color: #888888;
}
#margin-top{
margin-top: 10px;
}
#button-margin-top{
margin-top: 30px;
}
body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #0d0d0d;
}
.container-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 98.7vh;
}
.creation-container {
display: flex;
flex-direction: column;
align-items: center;
width: 80%;
padding: 20px;
background-color: #181818;
color: white;
border-radius: 5px;
height: fit-content;
max-height: 80vh;
min-height: 20%;
overflow-y: auto;
border: #222222 2px solid;
}
#signupForm {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
#error-message {
color: red;
opacity: 0;
position: absolute;
bottom: -0.1px;
margin-bottom: -0.1px;
top: 61.8%;
transition: 300ms;
}
.label {
font-size: 1.5em;
}
.textinput {
transition: 300ms;
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
background-color: #282828;
color: white;
border: #2a2a2a 2px solid;
box-sizing: border-box;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-size: 1.1em;
outline: none;
}
.textinput:focus {
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
outline: none;
}
.textarea {
transition: 300ms;
width: 100%;
min-width: 100%;
max-width: 100%;
min-height: auto;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
background-color: #282828;
color: white;
border: #2a2a2a 2px solid;
box-sizing: border-box;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-size: 1.08em;
outline: none;
}
.textarea:focus {
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
outline: none;
}
.button {
transition: 300ms;
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
background-color: #222222;
color: white;
border: #2a2a2a00 2px solid;
cursor: pointer;
font-size: 1.2em;
}
.button:hover {
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div {
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a {
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover {
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
.ccounter {
align-self: flex-end;
text-align: right;
margin-top: -2.2rem;
margin-right: 10px;
font-size: 1.1em;
color: #888888;
}
#margin-top {
margin-top: 10px;
}
#button-margin-top {
margin-top: 30px;
}
</style>
</html>
+1 -1
View File
@@ -147,7 +147,7 @@
max-width: 100%;
background-color: #222222;
border-radius: 5px;
padding: 20px;
padding: 26px;
height: fit-content;
height: 100%;
max-height: 100%;