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
+179 -42
View File
@@ -916,6 +916,17 @@ class Program
} }
} }
string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync();
try
{
JObject.Parse(requestBody);
}
catch
{
context.Response.StatusCode = 400;
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return;
}
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
@@ -987,7 +998,8 @@ class Program
punishedUsersCommand.Parameters.AddWithValue("@Punisher", loggedInUser.UUID); punishedUsersCommand.Parameters.AddWithValue("@Punisher", loggedInUser.UUID);
await punishedUsersCommand.ExecuteNonQueryAsync(); await punishedUsersCommand.ExecuteNonQueryAsync();
} }
Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] Account {user.Username}({user.UUID}) has been banned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}"); Console.WriteLine($"[{DateTime.Now}] Account {user.Username}({user.UUID}) has been banned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}");
await File.AppendAllTextAsync("logs.log", $"[{DateTime.Now}] Account {user.Username}({user.UUID}) has been banned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}\n");
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "User banned" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "User banned" }.ToString());
@@ -1040,7 +1052,17 @@ class Program
{ {
uploaderUUID = $"Anonymous-{Guid.NewGuid().ToString()}"; uploaderUUID = $"Anonymous-{Guid.NewGuid().ToString()}";
} }
try
{
JObject.Parse(requestBody);
}
catch
{
context.Response.StatusCode = 400;
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return;
}
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
var title = SanitizeInput(data["title"]?.ToString() ?? "Untitled"); var title = SanitizeInput(data["title"]?.ToString() ?? "Untitled");
var content = SanitizeInput(data["content"]?.ToString() ?? ""); var content = SanitizeInput(data["content"]?.ToString() ?? "");
@@ -1082,7 +1104,7 @@ class Program
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
string time = DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0).DateTime.ToString("yyyy-MM-dd HH:mm:ss"); string time = DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0).ToString().Split("+")[0].TrimEnd();
JObject responseJson = new JObject(); JObject responseJson = new JObject();
responseJson["pasteId"] = paste.Id; responseJson["pasteId"] = paste.Id;
@@ -1118,6 +1140,17 @@ class Program
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
try
{
JObject.Parse(requestBody);
}
catch
{
context.Response.StatusCode = 400;
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return;
}
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
var id = SanitizeInput(data["id"]?.ToString() ?? ""); var id = SanitizeInput(data["id"]?.ToString() ?? "");
if (string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id)) if (string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id))
@@ -1188,16 +1221,93 @@ class Program
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); try
var query = SanitizeInput(data["query"]?.ToString() ?? ""); {
Console.WriteLine($"erm: {query}"); JObject.Parse(requestBody);
if (string.IsNullOrEmpty(query) || string.IsNullOrWhiteSpace(query)) }
catch
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody);
var query = SanitizeInput(data["query"]?.ToString() ?? "");
if (string.IsNullOrEmpty(query) || string.IsNullOrWhiteSpace(query))
{
using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
{
await connection.OpenAsync();
var command = connection.CreateCommand();
command.CommandText = $"SELECT * FROM pastes WHERE Visibility != 'Private' ORDER BY UID DESC LIMIT 50";
var reader = await command.ExecuteReaderAsync();
string pastes = string.Empty;
JArray pastesArray = new JArray();
while (await reader.ReadAsync())
{
var paste = new Paste
{
Title = reader.GetString(1),
UnixDate = long.Parse(reader.GetString(2)),
Size = reader.GetString(3),
Visibility = reader.GetString(4),
Id = reader.GetString(5),
};
string title = paste.Title;
if (paste.Visibility == "Private" || paste.Visibility == "Unlisted")
{
continue;
}
if (paste.Title == "" || string.IsNullOrEmpty(paste.Title))
{
title = $"Untitled {reader.GetString(0)}";
}
if (paste.Title.Length > 40)
{
title = paste.Title.Substring(0, 40) + "...";
}
var difference = GetTimeDifference(DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0), DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.Now.ToUnixTimeSeconds()));
if (string.IsNullOrEmpty(parameters["html"]))
{
JObject pasteJson = new JObject();
pasteJson["title"] = paste.Title;
pasteJson["id"] = paste.Id;
pasteJson["size"] = ConvertToBytes(paste.Size);
pasteJson["date"] = difference;
pasteJson["visibility"] = paste.Visibility;
pastesArray.Add(pasteJson);
}
else
{
pastes += $"<a title=\"{paste.Title}\" href=\"/{paste.Id}\"><li>{title} {difference} {ConvertToBytes(paste.Size)}</li></a>";
}
}
if (string.IsNullOrEmpty(pastes) && pastesArray.Count == 0)
{
pastes = "<h2>No pastes found</h2>";
pastesArray.Add(new JObject { ["error"] = "No pastes found" });
context.Response.StatusCode = 404;
}
else
{
context.Response.StatusCode = 200;
}
if (string.IsNullOrEmpty(parameters["html"]))
{
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(pastesArray.ToString());
}
else
{
context.Response.ContentType = "text/html";
await context.Response.WriteAsync(pastes);
}
return;
}
}
using (var connection = new SqliteConnection("Data Source=pastes.sqlite")) using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
{ {
@@ -1255,7 +1365,19 @@ class Program
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
app.MapPost("/api/accounts/create", async (HttpContext context) => app.MapPost("/api/accounts/create", async (HttpContext context) =>
{ {
string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync();
try
{
JObject.Parse(requestBody);
}
catch
{
context.Response.StatusCode = 400;
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return;
}
Log log = await Logging.LogRequestAsync(context); Log log = await Logging.LogRequestAsync(context);
char[] disallowed = { ' ', '\'', '\"', '\\', '/', '(', ')', '[', ']', '{', '}', '<', '>', ';', ':', ',', '.', '!', '?', '@', '#', '$', '%', '^', '&', '*', '-', '+', '=', '~', '`' }; char[] disallowed = { ' ', '\'', '\"', '\\', '/', '(', ')', '[', ']', '{', '}', '<', '>', ';', ':', ',', '.', '!', '?', '@', '#', '$', '%', '^', '&', '*', '-', '+', '=', '~', '`' };
@@ -1300,9 +1422,9 @@ class Program
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid characters in username" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid characters in username" }.ToString());
return; return;
} }
string ip = Convert.ToBase64String(SHA1.HashData(Encoding.UTF8.GetBytes(log.IP))); string token = string.Empty;
string token = Convert.ToBase64String(Encoding.UTF8.GetBytes(BCrypt.Net.BCrypt.HashPassword(Guid.NewGuid().ToString()))); string ip = string.Empty;
string passwordHash = BCrypt.Net.BCrypt.HashPassword(password, salt); string passwordHash = string.Empty;
DateTime expirationDate = DateTime.Now.AddYears(1); DateTime expirationDate = DateTime.Now.AddYears(1);
using (var connection = new SqliteConnection("Data Source=pastes.sqlite")) using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
@@ -1324,6 +1446,10 @@ class Program
{ {
reader.Close(); reader.Close();
} }
ip = Convert.ToBase64String(SHA1.HashData(Encoding.UTF8.GetBytes(log.IP)));
token = Convert.ToBase64String(Encoding.UTF8.GetBytes(BCrypt.Net.BCrypt.HashPassword(Guid.NewGuid().ToString())));
passwordHash = BCrypt.Net.BCrypt.HashPassword(password, salt);
var insertCommand = connection.CreateCommand(); var insertCommand = connection.CreateCommand();
insertCommand.CommandText = "INSERT INTO users (UUID, Username, PasswordHash, CreationDate, LastLoginDate, Type, State) VALUES (@UUID, @Username, @PasswordHash, @CreationDate, @LastLoginDate, @Type, @State)"; insertCommand.CommandText = "INSERT INTO users (UUID, Username, PasswordHash, CreationDate, LastLoginDate, Type, State) VALUES (@UUID, @Username, @PasswordHash, @CreationDate, @LastLoginDate, @Type, @State)";
insertCommand.Parameters.AddWithValue("@UUID", Guid.NewGuid().ToString()); insertCommand.Parameters.AddWithValue("@UUID", Guid.NewGuid().ToString());
@@ -1356,36 +1482,47 @@ class Program
context.Response.Cookies.Append("token", token, cookie); context.Response.Cookies.Append("token", token, cookie);
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] Account {username} has been created"); Console.WriteLine($"[{DateTime.Now}] Account {username} has been created");
File.AppendAllText("logs.log", $"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] Account {username} has been created by {log.IP}\n"); File.AppendAllText("logs.log", $"[{DateTime.Now}] Account {username} has been created by {log.IP}\n");
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Account created" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Account created" }.ToString());
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
app.MapPost("/api/accounts/login", async (HttpContext Context) => app.MapPost("/api/accounts/login", (Delegate)(async (HttpContext context) =>
{ {
string requestBody = await new StreamReader(Context.Request.Body).ReadToEndAsync(); string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync();
Log log = await Logging.LogRequestAsync(Context); try
if (IsLoggedInAsync(Context.Request.Cookies["token"]).Result)
{ {
Context.Response.StatusCode = 400; JObject.Parse(requestBody);
Context.Response.ContentType = "application/json"; }
await Context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Already logged in" }.ToString()); catch
{
context.Response.StatusCode = 400;
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return;
}
Log log = await Logging.LogRequestAsync(context);
if (IsLoggedInAsync(context.Request.Cookies["token"]).Result)
{
context.Response.StatusCode = 400;
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Already logged in" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
Context.Response.StatusCode = 400; context.Response.StatusCode = 400;
Context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
if (!requestBody.Contains("username") || !requestBody.Contains("password") || Context.Request.ContentType != "application/json") if (!requestBody.Contains("username") || !requestBody.Contains("password") || context.Request.ContentType != "application/json")
{ {
Context.Response.StatusCode = 400; context.Response.StatusCode = 400;
Context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
@@ -1395,9 +1532,9 @@ class Program
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{ {
Context.Response.StatusCode = 400; context.Response.StatusCode = 400;
Context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString());
return; return;
} }
@@ -1414,9 +1551,9 @@ class Program
await reader.ReadAsync(); await reader.ReadAsync();
if (!reader.HasRows) if (!reader.HasRows)
{ {
Context.Response.StatusCode = 400; context.Response.StatusCode = 400;
Context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString());
return; return;
} }
if (BCrypt.Net.BCrypt.Verify(password, reader.GetString(3))) if (BCrypt.Net.BCrypt.Verify(password, reader.GetString(3)))
@@ -1448,22 +1585,22 @@ class Program
SameSite = SameSiteMode.Strict SameSite = SameSiteMode.Strict
}; };
Context.Response.Cookies.Append("token", token, cookie); context.Response.Cookies.Append("token", token, cookie);
Context.Response.StatusCode = 200; context.Response.StatusCode = 200;
Context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
Console.WriteLine($"[{DateTime.Now}] Account {username} has logged in"); Console.WriteLine($"[{DateTime.Now}] Account {username} has logged in");
File.AppendAllText("logs.log", $"[{DateTime.Now}] Account {username} has logged in from {log.IP}\n"); File.AppendAllText("logs.log", $"[{DateTime.Now}] Account {username} has logged in from {log.IP}\n");
await Context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Logged in" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Logged in" }.ToString());
return; return;
} }
else else
{ {
Context.Response.StatusCode = 400; context.Response.StatusCode = 400;
Context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString()); await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString());
} }
} }
}).RequireRateLimiting("fixed"); })).RequireRateLimiting("fixed");
#endregion #endregion
+3 -12
View File
@@ -12,25 +12,16 @@
"http": { "http": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"applicationUrl": "http://*:5240", "applicationUrl": "http://*:5240"
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}, },
"https": { "https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"applicationUrl": "https://*:7220;http://*:5240", "applicationUrl": "https://*:7220;http://*:5240"
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}, },
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
"launchBrowser": true, "launchBrowser": true
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
} }
} }
} }
+4 -4
View File
@@ -13,14 +13,14 @@
<None Remove="pastes\**" /> <None Remove="pastes\**" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project> </Project>
+192 -145
View File
@@ -1,11 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <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"> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
<title>create paste</title> <title>create paste</title>
</head> </head>
<body> <body>
<div class="nav-div"> <div class="nav-div">
<a href="/">home</a> <a href="/">home</a>
@@ -13,7 +15,7 @@
<a href="/archive">archive</a> <a href="/archive">archive</a>
{html} {html}
</div> </div>
<div class="container-wrapper"> <div class="container-wrapper">
<div class="dash-container"> <div class="dash-container">
<div class="wrapper"> <div class="wrapper">
<div class="idek-wrapper"> <div class="idek-wrapper">
@@ -37,6 +39,7 @@
<div class="idek-wrapper"> <div class="idek-wrapper">
<div class="accounts-wrapper"> <div class="accounts-wrapper">
<h3>Accounts</h3> <h3>Accounts</h3>
<input type="text" placeholder="search" class="text-input" oninput="search()">
<div class="list-container"> <div class="list-container">
{accounts} {accounts}
</div> </div>
@@ -53,160 +56,204 @@
return date.toLocaleString(); return date.toLocaleString();
} }
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function () {
const creationdateElement = document.getElementById('creationdate'); const creationdateElement = document.getElementById('creationdate');
const lastlogindateElement = document.getElementById('lastlogindate'); const lastlogindateElement = document.getElementById('lastlogindate');
const creationdateText = creationdateElement.innerText.trim(); const creationdateText = creationdateElement.innerText.trim();
const lastlogindateText = lastlogindateElement.innerText.trim(); const lastlogindateText = lastlogindateElement.innerText.trim();
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText)); creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
lastlogindateElement.innerText = "Last Login Date: " + localizeDateTime(parseInt(lastlogindateText)); 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> </script>
<style> <style>
.list-container {
max-height: 100%;
overflow-y: auto;
display: flex;
flex-direction: column;
width: 100%;
align-items: center;
}
.list-container{ body {
max-height: 100%; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
overflow-y: auto; font-weight: bold;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 100%; justify-content: center;
align-items: center; align-items: center;
justify-content: center; background-color: #0d0d0d;
} }
body{ .container-wrapper {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace; display: flex;
font-weight: bold; flex-direction: column;
display: flex; justify-content: center;
flex-direction: column; align-items: center;
justify-content: center; width: 100%;
align-items: center; height: 98.7vh;
background-color: #0d0d0d; }
}
.container-wrapper{ .dash-container {
display: flex; display: flex;
flex-direction: column; padding: 20px;
justify-content: center; background-color: #181818;
align-items: center; color: white;
width: 100%; border-radius: 5px;
height: 98.7vh; width: 80%;
} max-height: 80vh;
.dash-container { min-height: 20%;
display: flex; height: fit-content;
padding: 20px; border: #222222 2px solid;
background-color: #181818; }
color: white;
border-radius: 5px; .idek-wrapper {
width: 80%; display: flex;
max-height: 80vh; flex-direction: row;
min-height: 20%; width: 100%;
height: fit-content; }
border: #222222 2px solid;
} .account-info {
.idek-wrapper{ display: flex;
display: flex; flex-direction: column;
flex-direction: row; background-color: #222222;
width: 100%; width: 48%;
} padding: 20px;
.account-info{ margin-right: 5px;
display: flex; border-radius: 5px;
flex-direction: column; overflow-x: hidden;
background-color: #222222; overflow-y: auto;
width: 48%; }
padding: 20px;
margin-right: 5px; .pastes-wrapper {
border-radius: 5px; display: flex;
overflow-x: hidden; flex-direction: column;
overflow-y: auto; align-items: center;
} width: 48%;
.pastes-wrapper{ margin-left: 5px;
display: flex; border-radius: 5px;
flex-direction: column; padding: 20px;
align-items: center; overflow-x: hidden;
width: 48%; overflow-y: auto;
margin-left: 5px; background-color: #222222;
border-radius: 5px; max-height: 70vh;
padding: 20px; }
overflow-x: hidden;
overflow-y: auto; .accounts-wrapper {
background-color: #222222; margin-top: 10px;
max-height: 70vh; display: flex;
} flex-direction: column;
.accounts-wrapper{ align-items: center;
margin-top: 10px; width: 100%;
display: flex; border-radius: 5px;
flex-direction: column; padding: 20px;
align-items: center; overflow-x: hidden;
width: 100%; overflow-y: auto;
border-radius: 5px; background-color: #222222;
padding: 20px; max-height: 40vh;
overflow-x: hidden; }
overflow-y: auto;
background-color: #222222; .wrapper {
max-height: 70vh; display: flex;
} flex-direction: column;
.wrapper{ width: 100%;
display: flex; }
flex-direction: column;
width: 100%; .list-a {
} transition: 300ms;
.list-a{ text-decoration: none;
transition: 300ms; color: white;
text-decoration: none; width: 90%;
color: white; display: flex;
width: 90%; justify-content: center;
display: flex; align-items: center;
justify-content: center; padding: 10px;
align-items: center; border-radius: 5px;
padding: 10px; background-color: #2a2a2a;
border-radius: 5px; margin-top: 5px;
background-color: #2a2a2a; margin-bottom: 5px;
margin-top: 5px; border: #3a3a3a00 2px solid;
margin-bottom: 5px; }
border: #3a3a3a00 2px solid;
} .list-a:hover {
.list-a:hover{ transition: background-color 300ms;
transition: background-color 300ms; background-color: #333333;
background-color: #333333; border: #3a3a3a 2px solid;
border: #3a3a3a 2px solid; }
}
.list-item{ .list-item {
list-style: none; list-style: none;
} }
.nav-div{
top: 0; .text-input {
margin-top: 10px; transition: border 300ms;
position: absolute; width: 90.2%;
display: flex; height: 1.2rem;
flex-direction: row; padding: 10px;
justify-content: center; margin: 10px;
align-items: center; border-radius: 5px;
width: fit-content; border: #2a2a2a 2px solid;
background-color: #181818; background-color: #2a2a2a;
padding-left: 10px; color: white;
padding-right: 10px; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
color: white; }
border-radius: 5px;
height: fit-content; .text-input:focus {
overflow-y: auto; transition: border 300ms;
border: #222222 2px solid; outline: none;
} border: #333333 2px solid;
.nav-div a{ }
text-decoration: none;
color: white; .nav-div {
padding: 10px; top: 0;
margin: 10px; margin-top: 10px;
border-radius: 5px; position: absolute;
background-color: #222222; display: flex;
transition: 300ms; flex-direction: row;
border: #2a2a2a00 2px solid; justify-content: center;
} align-items: center;
.nav-div a:hover{ width: fit-content;
transition: 300ms; background-color: #181818;
background-color: #333333; padding-left: 10px;
border: #3a3a3a 2px solid; 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> </style>
</html> </html>
+1 -1
View File
@@ -139,7 +139,7 @@
border-radius: 5px; border-radius: 5px;
padding: 20px; padding: 20px;
height: fit-content; height: fit-content;
margin-top: 20px; margin-top: 26px;
height: 77.1%; height: 77.1%;
max-height: 77.1%; max-height: 77.1%;
} }
+60 -36
View File
@@ -32,54 +32,59 @@
</body> </body>
<script> <script>
let searchTimeout; let searchTimeout;
function search() { function search() {
clearTimeout(searchTimeout); clearTimeout(searchTimeout);
searchTimeout = setTimeout(searchPastes, 200); searchTimeout = setTimeout(searchPastes, 200);
} }
function searchPastes() { function searchPastes() {
const searchInput = document.querySelector('.text-input'); 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`, { fetch(`/api/pastes/search?html=true`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
query: searchInput.value query: searchInput.value
}) })
}) })
.then(response => response.text()) .then(response => response.text())
.then(data => { .then(data => {
const pastesWrapper = document.querySelector('.pastes-wrapper'); const pastesWrapper = document.querySelector('.pastes-wrapper');
if (data === '') { if (data === '') {
pastesWrapper.innerHTML = '<h1>no pastes found</h1>'; pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
return; return;
} }
pastesWrapper.innerHTML = data; pastesWrapper.innerHTML = data;
}); });
} }
</script> </script>
<style> <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 { body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold; font-weight: bold;
@@ -187,6 +192,25 @@
border: 2px solid #3a3a3a; 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 { .nav-div {
top: 0; top: 0;
margin-top: 10px; margin-top: 10px;
+3
View File
@@ -71,6 +71,9 @@ body{
width: 100%; width: 100%;
height: 98.7vh; height: 98.7vh;
} }
#pasteContent {
max-height: 500px;
}
.creation-container{ .creation-container{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
+24
View File
@@ -23,6 +23,7 @@
<input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50"> <input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50">
<button type="submit" class="button">Login</button> <button type="submit" class="button">Login</button>
</form> </form>
<h3 id="error-message"></h3>
</div> </div>
</div> </div>
</body> </body>
@@ -50,10 +51,20 @@
if (result.message != null) { if (result.message != null) {
window.location.href = "/"; 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> </script>
<style> <style>
body{ body{
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold; font-weight: bold;
@@ -85,6 +96,7 @@ body{
min-height: 20%; min-height: 20%;
overflow-y: auto; overflow-y: auto;
border: #222222 2px solid; border: #222222 2px solid;
position: relative;
} }
#loginForm{ #loginForm{
display: flex; display: flex;
@@ -92,6 +104,16 @@ body{
align-items: center; align-items: center;
width: 100%; width: 100%;
} }
#error-message{
color: red;
opacity: 0;
position: absolute;
bottom: -0.1px;
margin-bottom: -0.1px;
top: 88%;
transition: 300ms;
}
.label{ .label{
font-size: 1.5em; font-size: 1.5em;
} }
@@ -152,6 +174,8 @@ body{
border: #2a2a2a00 2px solid; border: #2a2a2a00 2px solid;
cursor: pointer; cursor: pointer;
font-size: 1.2em; font-size: 1.2em;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
} }
.button:hover{ .button:hover{
transition: 300ms; transition: 300ms;
+193 -154
View File
@@ -1,11 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <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"> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
<title>create paste</title> <title>create paste</title>
</head> </head>
<body> <body>
<div class="nav-div"> <div class="nav-div">
<a href="/">home</a> <a href="/">home</a>
@@ -13,18 +15,19 @@
<a href="/archive">archive</a> <a href="/archive">archive</a>
{html} {html}
</div> </div>
<div class="container-wrapper"> <div class="container-wrapper">
<div class="creation-container"> <div class="creation-container">
<h1>sign-up</h1> <h1>sign-up</h1>
<form id="signupForm"> <form id="signupForm">
<label for="usernameTitle" class="label" onforminput="">Username</label> <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 id="characterCount" for="characterCount" class="ccounter">0/20</label>
<label for="passwordTitle" class="label" id="margin-top">Password</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> <label id="passcharacterCount" for="characterCount" class="ccounter">0/20</label>
<button type="submit" class="button" id="button-margin-top">Sign-up</button> <button type="submit" class="button" id="button-margin-top">Sign-up</button>
</form> </form>
<h3 id="error-message"></h3>
</div> </div>
</div> </div>
</body> </body>
@@ -52,6 +55,15 @@
if (result.message != null) { if (result.message != null) {
window.location.href = "/"; 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) { document.getElementById("usernameInput").addEventListener("input", function (event) {
@@ -66,156 +78,183 @@
}); });
</script> </script>
<style> <style>
body{ body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold; font-weight: bold;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-color: #0d0d0d; background-color: #0d0d0d;
} }
.container-wrapper{
display: flex; .container-wrapper {
flex-direction: column; display: flex;
justify-content: center; flex-direction: column;
align-items: center; justify-content: center;
width: 100%; align-items: center;
height: 98.7vh; width: 100%;
} height: 98.7vh;
.creation-container{ }
display: flex;
flex-direction: column; .creation-container {
align-items: center; display: flex;
width: 80%; flex-direction: column;
padding: 20px; align-items: center;
background-color: #181818; width: 80%;
color: white; padding: 20px;
border-radius: 5px; background-color: #181818;
height: fit-content; color: white;
max-height: 80vh; border-radius: 5px;
min-height: 20%; height: fit-content;
overflow-y: auto; max-height: 80vh;
border: #222222 2px solid; min-height: 20%;
} overflow-y: auto;
#signupForm{ border: #222222 2px solid;
display: flex; }
flex-direction: column;
align-items: center; #signupForm {
width: 100%; display: flex;
} flex-direction: column;
.label{ align-items: center;
font-size: 1.5em; width: 100%;
} }
.textinput{
transition: 300ms; #error-message {
width: 100%; color: red;
padding: 10px; opacity: 0;
margin: 10px 0; position: absolute;
border-radius: 5px; bottom: -0.1px;
border: none; margin-bottom: -0.1px;
background-color: #282828; top: 61.8%;
color: white; transition: 300ms;
border: #2a2a2a 2px solid; }
box-sizing: border-box;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace; .label {
font-size: 1.1em; font-size: 1.5em;
outline: none; }
}
.textinput:focus{ .textinput {
transition: 300ms; transition: 300ms;
background-color: #333333; width: 100%;
border: 2px solid #3a3a3a; padding: 10px;
outline: none; margin: 10px 0;
} border-radius: 5px;
.textarea{ border: none;
transition: 300ms; background-color: #282828;
width: 100%; color: white;
min-width: 100%; border: #2a2a2a 2px solid;
max-width: 100%; box-sizing: border-box;
min-height: auto; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
padding: 10px; font-size: 1.1em;
margin: 10px 0; outline: none;
border-radius: 5px; }
border: none;
background-color: #282828; .textinput:focus {
color: white; transition: 300ms;
border: #2a2a2a 2px solid; background-color: #333333;
box-sizing: border-box; border: 2px solid #3a3a3a;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace; outline: none;
font-size: 1.08em; }
outline: none;
} .textarea {
.textarea:focus{ transition: 300ms;
transition: 300ms; width: 100%;
background-color: #333333; min-width: 100%;
border: 2px solid #3a3a3a; max-width: 100%;
outline: none; min-height: auto;
} padding: 10px;
.button{ margin: 10px 0;
transition: 300ms; border-radius: 5px;
width: 100%; border: none;
padding: 10px; background-color: #282828;
margin: 10px 0; color: white;
border-radius: 5px; border: #2a2a2a 2px solid;
border: none; box-sizing: border-box;
background-color: #222222; font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
color: white; font-size: 1.08em;
border: #2a2a2a00 2px solid; outline: none;
cursor: pointer; }
font-size: 1.2em;
} .textarea:focus {
.button:hover{ transition: 300ms;
transition: 300ms; background-color: #333333;
background-color: #333333; border: 2px solid #3a3a3a;
border: 2px solid #3a3a3a; outline: none;
} }
.nav-div{
top: 0; .button {
margin-top: 10px; transition: 300ms;
position: absolute; width: 100%;
display: flex; padding: 10px;
flex-direction: row; margin: 10px 0;
justify-content: center; border-radius: 5px;
align-items: center; border: none;
width: fit-content; background-color: #222222;
background-color: #181818; color: white;
padding-left: 10px; border: #2a2a2a00 2px solid;
padding-right: 10px; cursor: pointer;
color: white; font-size: 1.2em;
border-radius: 5px; }
height: fit-content;
overflow-y: auto; .button:hover {
border: #222222 2px solid; transition: 300ms;
} background-color: #333333;
.nav-div a{ border: 2px solid #3a3a3a;
text-decoration: none; }
color: white;
padding: 10px; .nav-div {
margin: 10px; top: 0;
border-radius: 5px; margin-top: 10px;
background-color: #222222; position: absolute;
transition: 300ms; display: flex;
border: #2a2a2a00 2px solid; flex-direction: row;
} justify-content: center;
.nav-div a:hover{ align-items: center;
transition: 300ms; width: fit-content;
background-color: #333333; background-color: #181818;
border: #3a3a3a 2px solid; padding-left: 10px;
} padding-right: 10px;
.ccounter{ color: white;
align-self: flex-end; border-radius: 5px;
text-align: right; height: fit-content;
margin-top: -2.2rem; overflow-y: auto;
margin-right: 10px; border: #222222 2px solid;
font-size: 1.1em; }
color: #888888;
} .nav-div a {
#margin-top{ text-decoration: none;
margin-top: 10px; color: white;
} padding: 10px;
#button-margin-top{ margin: 10px;
margin-top: 30px; 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> </style>
</html> </html>
+1 -1
View File
@@ -147,7 +147,7 @@
max-width: 100%; max-width: 100%;
background-color: #222222; background-color: #222222;
border-radius: 5px; border-radius: 5px;
padding: 20px; padding: 26px;
height: fit-content; height: fit-content;
height: 100%; height: 100%;
max-height: 100%; max-height: 100%;