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
+332 -96
View File
@@ -45,6 +45,7 @@ namespace SharpbinV2.Server
"xml" "xml"
}; };
public static string HMACSecret = "thisneedstobechanged"; public static string HMACSecret = "thisneedstobechanged";
public static JObject Configuration { get; set; }
static async Task Main(string[] args) static async Task Main(string[] args)
{ {
@@ -52,7 +53,14 @@ namespace SharpbinV2.Server
var logger = new Logging(); var logger = new Logging();
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables(); builder.Configuration.AddEnvironmentVariables();
builder.WebHost.UseUrls($"https://*:{Environment.GetEnvironmentVariable("HTTPS_Port") ?? "5820"}", $"http://*:{Environment.GetEnvironmentVariable("HTTP_Port") ?? "5810"}"); if (Environment.GetEnvironmentVariable("HTTPS") == "true")
{
builder.WebHost.UseUrls($"https://*:{Environment.GetEnvironmentVariable("HTTPS_Port") ?? "5820"}");
}
else
{
builder.WebHost.UseUrls($"http://*:{Environment.GetEnvironmentVariable("HTTP_Port") ?? "5810"}");
}
MaxFileSize = Environment.GetEnvironmentVariable("MAX_FILE_SIZE") != null ? Convert.ToInt64(Environment.GetEnvironmentVariable("MAX_FILE_SIZE")) : MaxFileSize; MaxFileSize = Environment.GetEnvironmentVariable("MAX_FILE_SIZE") != null ? Convert.ToInt64(Environment.GetEnvironmentVariable("MAX_FILE_SIZE")) : MaxFileSize;
HMACSecret = Environment.GetEnvironmentVariable("HMAC_SECRET") ?? HMACSecret; HMACSecret = Environment.GetEnvironmentVariable("HMAC_SECRET") ?? HMACSecret;
if (HMACSecret == "thisneedstobechanged") if (HMACSecret == "thisneedstobechanged")
@@ -229,6 +237,29 @@ namespace SharpbinV2.Server
context.Response.Headers.Add("Content-Type", "text/html"); context.Response.Headers.Add("Content-Type", "text/html");
await context.Response.SendFileAsync("wwwroot/archive.html"); await context.Response.SendFileAsync("wwwroot/archive.html");
}); });
app.MapGet("/dash", async (HttpContext context) =>
{
context.Response.StatusCode = 200;
context.Response.Headers.Add("Content-Type", "text/html");
await context.Response.SendFileAsync("wwwroot/dash.html");
});
app.MapGet("/dash.html", (HttpContext context) =>
{
context.Response.Redirect("/dash");
});
app.MapGet("/login", async (HttpContext context) =>
{
context.Response.StatusCode = 200;
context.Response.Headers.Add("Content-Type", "text/html");
await context.Response.SendFileAsync("wwwroot/login.html");
});
app.MapGet("/register", async (HttpContext context) =>
{
context.Response.StatusCode = 200;
context.Response.Headers.Add("Content-Type", "text/html");
await context.Response.SendFileAsync("wwwroot/register.html");
});
#endregion #endregion
#region API #region API
@@ -324,15 +355,17 @@ namespace SharpbinV2.Server
logger.LogInfo($"Account {username} has been created."); logger.LogInfo($"Account {username} has been created.");
return; return;
}); });
app.MapGet("/api/accounts/login", async (HttpContext context) => app.MapPost("/api/accounts/login", async (HttpContext context) =>
{ {
var requestdetails = GetRequestDetails(context); var requestdetails = GetRequestDetails(context);
if (!string.IsNullOrEmpty(requestdetails.Token) && Database.UserFromToken(requestdetails.Token) != null) var __user = await Database.UserFromToken(requestdetails.Token);
if (!string.IsNullOrEmpty(requestdetails.Token) && __user != null)
{ {
context.Response.StatusCode = 200; context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = true, message = "Already logged in." }); await context.Response.WriteAsJsonAsync(new { success = false, message = "Already logged in." });
return; return;
} }
var body = await new StreamReader(context.Request.Body).ReadToEndAsync(); var body = await new StreamReader(context.Request.Body).ReadToEndAsync();
if (body == null) if (body == null)
{ {
@@ -425,14 +458,14 @@ namespace SharpbinV2.Server
if (string.IsNullOrEmpty(requestdetails.Token)) if (string.IsNullOrEmpty(requestdetails.Token))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Not authorized." }); await context.Response.WriteAsJsonAsync(new { success = false, message = "No token provided, not authorized." });
return; return;
} }
var user = await Database.UserFromToken(requestdetails.Token); var user = await Database.UserFromToken(requestdetails.Token);
if (user == null) if (user == null)
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Not authorized." }); await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." });
return; return;
} }
var cleanuser = new User var cleanuser = new User
@@ -440,6 +473,7 @@ namespace SharpbinV2.Server
UID = user.UID, UID = user.UID,
UUID = user.UUID, UUID = user.UUID,
Username = user.Username, Username = user.Username,
Email = user.Email,
DisplayName = user.DisplayName, DisplayName = user.DisplayName,
Created = user.Created, Created = user.Created,
LastLogin = user.LastLogin LastLogin = user.LastLogin
@@ -448,6 +482,74 @@ namespace SharpbinV2.Server
await context.Response.WriteAsJsonAsync(new { success = true, user = cleanuser }); await context.Response.WriteAsJsonAsync(new { success = true, user = cleanuser });
return; return;
}); });
app.MapPost("/api/accounts/delete", async (HttpContext context) =>
{
var requestdetails = GetRequestDetails(context);
if (string.IsNullOrEmpty(requestdetails.Token))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "No token provided, not authorized." });
return;
}
var user = await Database.UserFromToken(requestdetails.Token);
if (user == null)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." });
return;
}
using (var connection = new SqliteConnection(MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "DELETE FROM users WHERE UUID = @UUID;";
command.Parameters.AddWithValue("@UUID", user.UUID);
await command.ExecuteNonQueryAsync();
}
await connection.CloseAsync();
}
using (var connection = new SqliteConnection(MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "DELETE FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
await command.ExecuteNonQueryAsync();
}
await connection.CloseAsync();
}
using (var connection = new SqliteConnection(MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "DELETE FROM sessions WHERE UserUUID = @UserUUID;";
command.Parameters.AddWithValue("@UserUUID", user.UUID);
await command.ExecuteNonQueryAsync();
}
await connection.CloseAsync();
}
using (var connection = new SqliteConnection(MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "UPDATE views SET UserUUID = @UserUUID WHERE UserUUID = @OldUserUUID;";
command.Parameters.AddWithValue("@UserUUID", "0");
command.Parameters.AddWithValue("@OldUserUUID", user.UUID);
await command.ExecuteNonQueryAsync();
}
await connection.CloseAsync();
}
context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, message = "Account deleted." });
});
app.MapPost("/api/pastes/create", async (HttpContext context) => app.MapPost("/api/pastes/create", async (HttpContext context) =>
{ {
@@ -537,59 +639,7 @@ namespace SharpbinV2.Server
paste.FilePath = null; paste.FilePath = null;
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, message = "Paste created.", paste = paste }); await context.Response.WriteAsJsonAsync(new { success = true, message = "Paste created.", paste = paste });
logger.LogInfo($"A Paste of {FormatBytes(paste.Size)} was created by {paste.UUID}"); logger.LogInfo($"A Paste of {FormatBytes(paste.Size ?? 0)} was created by {paste.UUID}");
return;
});
app.MapGet("/api/pastes/{pasteid}/info", async (HttpContext context) =>
{
var pasteid = context.Request.RouteValues["pasteid"].ToString() ?? null;
if (string.IsNullOrEmpty(pasteid))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid Paste ID." });
return;
}
var paste = await Database.GetPasteFromID(pasteid);
if (paste == null)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Paste not found." });
return;
}
if (paste.AuthorUUID != "0")
{
var user = await Database.UserFromUUID(paste.AuthorUUID);
paste.AuthorUUID = user.Username;
}
else
{
paste.AuthorUUID = "Anonymous";
}
paste.FilePath = null;
context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, paste = paste });
});
app.MapGet("/api/pastes/{pasteid}", async (HttpContext context) =>
{
var pasteid = context.Request.RouteValues["pasteid"].ToString() ?? null;
if (string.IsNullOrEmpty(pasteid))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid Paste ID." });
return;
}
var paste = await Database.GetPasteFromID(pasteid);
context.Response.StatusCode = 200;
context.Response.Headers.Add("Content-Type", "text/plain");
if (paste.FilePath.EndsWith(".gz"))
{
context.Response.Headers.Add("Content-Encoding", "gzip");
await context.Response.SendFileAsync(paste.FilePath);
}
else
{
await context.Response.SendFileAsync(paste.FilePath);
}
return; return;
}); });
app.MapGet("/api/pastes/archive", async (HttpContext context) => app.MapGet("/api/pastes/archive", async (HttpContext context) =>
@@ -660,6 +710,142 @@ namespace SharpbinV2.Server
} }
} }
}); });
app.MapGet("/api/pastes/my", async (HttpContext context) =>
{
var requestdetails = GetRequestDetails(context);
if (string.IsNullOrEmpty(requestdetails.Token))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Not authorized." });
return;
}
var user = await Database.UserFromToken(requestdetails.Token);
if (user == null)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." });
return;
}
var queries = context.Request.Query;
if (!queries.ContainsKey("page") && !queries.ContainsKey("limit"))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Missing required fields." });
return;
}
var page = queries.ContainsKey("page") ? Convert.ToInt32(queries["page"]) : 0;
var limit = queries.ContainsKey("limit") ? Convert.ToInt32(queries["limit"]) : 10;
if (page < 0 || limit <= 0 || limit > 25)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid page or limit." });
return;
}
int pages = await Database.EnumerateUserPastes(user) / limit;
if (page > pages)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Page out of range.", pages });
return;
}
using (var connection = new SqliteConnection(MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM pastes WHERE AuthorUUID = @AuthorUUID ORDER BY Created DESC LIMIT @Limit OFFSET @Offset;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
command.Parameters.AddWithValue("@Limit", limit);
command.Parameters.AddWithValue("@Offset", page * limit);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, error = true, message = "No pastes found." });
return;
}
var pastes = new List<Paste>();
while (await reader.ReadAsync())
{
pastes.Add(new Paste
{
UUID = reader.GetString(1),
ID = reader.GetString(2),
Visibility = reader.GetInt32(3),
Title = reader.IsDBNull(4) ? null : reader.GetString(4),
AuthorUUID = reader.GetString(5),
Created = reader.GetInt64(7),
Edited = reader.GetInt64(8),
Size = reader.GetInt32(9),
TrueSize = reader.GetInt32(10),
Views = reader.GetInt32(11),
Syntax = reader.IsDBNull(12) ? null : reader.GetString(12)
});
}
context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, pastes, pages });
return;
}
}
}
});
app.MapGet("/api/pastes/{pasteid}/info", async (HttpContext context) =>
{
var pasteid = context.Request.RouteValues["pasteid"].ToString() ?? null;
if (string.IsNullOrEmpty(pasteid))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid Paste ID." });
return;
}
var paste = await Database.GetPasteFromID(pasteid);
if (paste == null)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Paste not found." });
return;
}
if (paste.AuthorUUID != "0")
{
var user = await Database.UserFromUUID(paste.AuthorUUID);
paste.AuthorUUID = user.Username;
}
else
{
paste.AuthorUUID = "Anonymous";
}
paste.FilePath = null;
context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, paste = paste });
});
app.MapGet("/api/pastes/{pasteid}", async (HttpContext context) =>
{
var pasteid = context.Request.RouteValues["pasteid"].ToString() ?? null;
if (string.IsNullOrEmpty(pasteid))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid Paste ID." });
return;
}
var paste = await Database.GetPasteFromID(pasteid);
context.Response.StatusCode = 200;
context.Response.Headers.Add("Content-Type", "text/plain");
if (paste.FilePath.EndsWith(".gz"))
{
context.Response.Headers.Add("Content-Encoding", "gzip");
await context.Response.SendFileAsync(paste.FilePath);
}
else
{
await context.Response.SendFileAsync(paste.FilePath);
}
return;
});
#endregion #endregion
@@ -933,7 +1119,6 @@ namespace SharpbinV2.Server
return null; return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection)) using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{ {
await connection.OpenAsync(); await connection.OpenAsync();
using (var command = connection.CreateCommand()) using (var command = connection.CreateCommand())
{ {
@@ -944,7 +1129,7 @@ namespace SharpbinV2.Server
if (!reader.HasRows) if (!reader.HasRows)
return null; return null;
await reader.ReadAsync(); await reader.ReadAsync();
return await UserFromUUID(reader.GetString(2)); return await UserFromUUID(reader.GetString(1));
} }
} }
} }
@@ -961,6 +1146,21 @@ namespace SharpbinV2.Server
} }
} }
} }
public static async Task<int> EnumerateUserPastes(User user)
{
if (user == null)
return 0;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
return Convert.ToInt32(await command.ExecuteScalarAsync());
}
}
}
public static async Task<Paste> GetPasteFromID(string id) public static async Task<Paste> GetPasteFromID(string id)
{ {
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
@@ -1053,6 +1253,45 @@ namespace SharpbinV2.Server
await connection.CloseAsync(); await connection.CloseAsync();
} }
} }
public static async Task <List<Paste>> PastesFromUser(User user)
{
if (user == null)
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
var pastes = new List<Paste>();
while (await reader.ReadAsync())
{
pastes.Add(new Paste
{
UUID = reader.GetString(1),
ID = reader.GetString(2),
Visibility = reader.GetInt32(3),
Title = reader.IsDBNull(4) ? null : reader.GetString(4),
AuthorUUID = reader.GetString(5),
FilePath = reader.GetString(6),
Created = reader.GetInt64(7),
Edited = reader.GetInt64(8),
Size = reader.GetInt32(9),
TrueSize = reader.GetInt32(10),
Views = reader.GetInt32(11),
Syntax = reader.IsDBNull(12) ? null : reader.GetString(12)
});
}
return pastes;
}
}
}
}
} }
public class Logging public class Logging
{ {
@@ -1122,7 +1361,6 @@ namespace SharpbinV2.Server
} }
return compressedBytes; return compressedBytes;
} }
public static async Task<string> DecompressByteArrayToString(byte[] compressedBytes) public static async Task<string> DecompressByteArrayToString(byte[] compressedBytes)
{ {
string decompressedText; string decompressedText;
@@ -1138,7 +1376,6 @@ namespace SharpbinV2.Server
} }
return decompressedText; return decompressedText;
} }
public static async Task<byte[]> DecompressByteArray(byte[] compressedBytes) public static async Task<byte[]> DecompressByteArray(byte[] compressedBytes)
{ {
byte[] decompressedBytes; byte[] decompressedBytes;
@@ -1169,7 +1406,6 @@ namespace SharpbinV2.Server
return compressionRatio < ratioThreshold; return compressionRatio < ratioThreshold;
} }
public static bool IsCompressed(byte[] data) public static bool IsCompressed(byte[] data)
{ {
return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B; return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
@@ -1177,45 +1413,45 @@ namespace SharpbinV2.Server
} }
class User class User
{ {
public int UID { get; set; } public int? UID { get; set; }
public string UUID { get; set; } public string? UUID { get; set; }
public int Type { get; set; } public int? Type { get; set; }
public string Email { get; set; } public string? Email { get; set; }
public string Username { get; set; } public string? Username { get; set; }
public string DisplayName { get; set; } public string? DisplayName { get; set; }
public string Password { get; set; } public string? Password { get; set; }
public long Created { get; set; } public long? Created { get; set; }
public long LastLogin { get; set; } public long? LastLogin { get; set; }
} }
class Paste class Paste
{ {
public string UUID { get; set; } public string? UUID { get; set; }
public string ID { get; set; } public string? ID { get; set; }
public int Visibility { get; set; } public int? Visibility { get; set; }
public string Title { get; set; } public string? Title { get; set; }
public string AuthorUUID { get; set; } public string? AuthorUUID { get; set; }
public string FilePath { get; set; } public string? FilePath { get; set; }
public long Created { get; set; } public long? Created { get; set; }
public long Edited { get; set; } public long? Edited { get; set; }
public int Size { get; set; } public int? Size { get; set; }
public int TrueSize { get; set; } public int? TrueSize { get; set; }
public int Views { get; set; } public int? Views { get; set; }
public string Syntax { get; set; } public string? Syntax { get; set; }
} }
class Session class Session
{ {
public string UUID { get; set; } public string? UUID { get; set; }
public string UserUUID { get; set; } public string? UserUUID { get; set; }
public string Token { get; set; } public string? Token { get; set; }
public long Created { get; set; } public long? Created { get; set; }
public long Expirary { get; set; } public long? Expirary { get; set; }
public string Ip { get; set; } public string? Ip { get; set; }
public string UserAgent { get; set; } public string? UserAgent { get; set; }
} }
class RequestDetails class RequestDetails
{ {
public string Ip { get; set; } public string? Ip { get; set; }
public string UserAgent { get; set; } public string? UserAgent { get; set; }
public string Token { get; set; } public string? Token { get; set; }
} }
} }
+24
View File
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpbinV2.Server", "SharpbinV2.Server.csproj", "{68738FF4-A603-C797-2A44-D510EF342839}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68738FF4-A603-C797-2A44-D510EF342839}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68738FF4-A603-C797-2A44-D510EF342839}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68738FF4-A603-C797-2A44-D510EF342839}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68738FF4-A603-C797-2A44-D510EF342839}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4E1CB94E-6A3B-4EDF-95C2-479B8817C596}
EndGlobalSection
EndGlobal
+4 -10
View File
@@ -24,21 +24,15 @@
<p id="archive-syntax">Syntax</p> <p id="archive-syntax">Syntax</p>
</div> </div>
<ol class="archive-list" id="archives"> <ol class="archive-list" id="archives">
<!-- <li>
<a href="paste.html?id=1">
<p id="archive-title">Title</p>
<p id="archive-date">Date</p>
<p id="archive-syntax">Syntax</p>
</a>
</li> -->
</ol> </ol>
<div class="paste-actions"> <div class="paste-actions">
<button id="previous-button" onclick="previousPage()">&lt;</button> <button id="previous-button" onclick="previousPage()">&larr; Previous</button>
<p id="paste-pages">0/0</p> <p id="paste-pages">0/0</p>
<button id="next-button" onclick="nextPage()">></button> <button id="next-button" onclick="nextPage()">Next &rarr;</button>
</div> </div>
</div> </div>
</body>
<script src="js/archive.js"></script> <script src="js/archive.js"></script>
<script src="js/navbar.js"></script> <script src="js/navbar.js"></script>
</body>
</html> </html>
+182 -39
View File
@@ -1,62 +1,205 @@
.main-container {
max-width: 80%;
margin: 2rem auto;
padding: 1.5rem;
background-color: var(--neutral-900);
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
#archive-header {
font-size: 2rem;
font-weight: 700;
margin-bottom: 1.5rem;
color: var(--neutral-50);
text-align: center;
letter-spacing: 0.5px;
}
.archive-information {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
gap: 1rem;
padding: 0.75rem 1rem;
margin-bottom: 1rem;
background-color: var(--neutral-800);
border-radius: 6px;
font-weight: 600;
color: var(--neutral-200);
border-bottom: 2px solid var(--neutral-700);
width: 100%;
}
.archive-information p {
margin: 0;
}
.archive-list { .archive-list {
list-style-type: none; list-style-type: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
width: 100%; width: 100%;
max-height: 100%; max-height: 70vh;
overflow-y: scroll; overflow-y: auto;
border-radius: 6px;
scrollbar-width: thin;
scrollbar-color: var(--neutral-700) var(--neutral-900);
} }
.archive-list::-webkit-scrollbar {
width: 8px;
}
.archive-list::-webkit-scrollbar-track {
background: var(--neutral-900);
border-radius: 6px;
}
.archive-list::-webkit-scrollbar-thumb {
background-color: var(--neutral-700);
border-radius: 6px;
}
.archive-list li { .archive-list li {
margin: 5px 0 5px 0; margin: 0.75rem 0;
padding: 0; transition: transform 0.2s ease;
width: 100%;
} }
.archive-list li:hover {
transform: translateY(-2px);
}
.archive-list li a { .archive-list li a {
display: block; display: grid;
padding: 1rem; grid-template-columns: 2fr 1fr 1fr;
gap: 1rem;
padding: 1rem 1.25rem;
background-color: var(--neutral-800); background-color: var(--neutral-800);
color: var(--neutral-50); color: var(--neutral-50);
text-decoration: none; text-decoration: none;
transition: background-color 0.3s; transition: all 0.3s ease;
border-radius: 5px; border-radius: 6px;
border: 1px solid var(--neutral-700); border: 1px solid var(--neutral-700);
width: 100%; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
display: flex;
justify-content: space-between;
}
#archive-title {
min-width: 50%;
max-width: 50%;
}
.archive-information {
padding: 0 2px 0 2px;
width: 100%;
display: flex;
justify-content: space-between;
}
.main-container {
max-height: 80% !important;
}
.paste-actions {
width: 100%;
margin-top: 5px;
display: flex;
justify-content: space-between;
align-items: center;
} }
button { .archive-list li a:hover {
padding: 10px 40px 10px 40px; background-color: var(--neutral-750);
margin: 5px 0; border-color: var(--neutral-600);
border-radius: 5px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border: 1px solid var(--neutral-800); }
.archive-list li a p {
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#archive-title {
font-weight: 500;
color: var(--neutral-100);
}
#archive-date {
color: var(--neutral-300);
font-size: 0.9rem;
text-align: center;
}
#archive-syntax {
color: var(--neutral-300);
font-size: 0.9rem;
text-align: right;
}
.paste-actions {
width: 100%;
margin-top: 1.5rem;
display: flex;
justify-content: center;
align-items: center;
gap: 1.5rem;
}
.paste-actions button {
padding: 0.6rem 1.2rem;
border-radius: 6px;
border: 1px solid var(--neutral-700);
background-color: var(--neutral-800); background-color: var(--neutral-800);
color: var(--neutral-50); color: var(--neutral-50);
cursor: pointer; cursor: pointer;
transition: background-color 0.3s; transition: all 0.2s ease;
font-size: 1rem; font-size: 1rem;
min-width: 100px;
display: flex;
align-items: center;
justify-content: center;
} }
button:hover { .paste-actions button:hover:not(:disabled) {
background-color: var(--neutral-700); background-color: var(--neutral-700);
transform: translateY(-2px);
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}
.paste-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
#paste-pages {
font-weight: 500;
color: var(--neutral-300);
font-size: 1.1rem;
margin: 0;
padding: 0.5rem 1rem;
background-color: var(--neutral-800);
border-radius: 6px;
min-width: 80px;
text-align: center;
}
@media (max-width: 768px) {
.archive-information,
.archive-list li a {
grid-template-columns: 3fr 2fr;
}
#archive-syntax {
display: none;
}
.archive-information p:last-child {
display: none;
}
.paste-actions button {
padding: 0.5rem 1rem;
min-width: 80px;
}
}
@media (max-width: 480px) {
.main-container {
padding: 1rem;
margin: 1rem;
}
#archive-header {
font-size: 1.5rem;
}
.archive-list {
max-height: 60vh;
}
.paste-actions {
gap: 0.75rem;
}
#paste-pages {
min-width: 60px;
font-size: 0.9rem;
}
} }
+149
View File
@@ -0,0 +1,149 @@
.auth-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
background-color: var(--neutral-950);
}
.auth-form-container {
background-color: var(--neutral-900);
border-radius: 8px;
padding: 30px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 450px;
border: 1px solid var(--neutral-800);
}
.auth-title {
text-align: center;
font-size: 1.8rem;
font-weight: 600;
margin-bottom: 24px;
color: var(--neutral-100);
}
.auth-form {
display: flex;
flex-direction: column;
gap: 20px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-size: 0.9rem;
font-weight: 500;
color: var(--neutral-300);
}
.form-group input {
padding: 12px 16px;
border-radius: 6px;
border: 1px solid var(--neutral-700);
background-color: var(--neutral-800);
color: var(--neutral-100);
font-size: 1rem;
transition: all 0.2s ease;
}
.form-group input:focus {
outline: none;
border-color: var(--neutral-500);
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
}
.auth-button {
margin-top: 10px;
padding: 12px;
border-radius: 6px;
border: none;
background-color: var(--neutral-700);
color: var(--neutral-50);
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.auth-button:hover {
background-color: var(--neutral-600);
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.auth-links {
margin-top: 24px;
text-align: center;
display: flex;
flex-direction: column;
gap: 10px;
}
.auth-links p {
color: var(--neutral-400);
margin: 0;
}
.auth-links a {
color: var(--neutral-300);
text-decoration: none;
font-weight: 500;
transition: color 0.2s ease;
}
.auth-links a:hover {
color: var(--neutral-100);
text-decoration: underline;
}
.error-message {
background-color: rgba(220, 38, 38, 0.1);
color: #ef4444;
padding: 10px 16px;
border-radius: 6px;
margin-bottom: 16px;
font-size: 0.9rem;
display: none;
border: 1px solid rgba(220, 38, 38, 0.2);
}
.error-message.visible {
display: block;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 480px) {
.auth-form-container {
padding: 20px;
}
.auth-title {
font-size: 1.6rem;
}
.form-group input {
padding: 10px 12px;
}
.auth-button {
padding: 10px;
}
}
+455
View File
@@ -0,0 +1,455 @@
body {
background-color: var(--neutral-950);
color: var(--neutral-100);
}
.main-container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: stretch;
margin-top: 2rem;
min-height: 400px;
padding: 20px;
gap: 25px;
}
.account-info, .paste-list {
width: 48%;
border-radius: 8px;
padding: 25px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
background-color: var(--neutral-900);
border: 1px solid var(--neutral-700);
transition: all 0.3s ease;
}
.paste-list {
display: flex;
flex-direction: column;
}
.account-info {
display: flex;
flex-direction: column;
}
.account-info:hover, .paste-list:hover {
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
border-color: var(--neutral-700);
}
.account-info h1, .paste-list h1 {
margin-bottom: 25px;
color: var(--neutral-100);
text-align: center;
font-size: 1.8rem;
border-bottom: 2px solid var(--neutral-700);
padding-bottom: 10px;
}
.account-info p {
margin: 12px 0;
padding: 8px;
border-bottom: 1px solid var(--neutral-800);
font-size: 1.05rem;
display: flex;
justify-content: space-between;
color: var(--neutral-300);
}
.paste-information {
display: flex;
justify-content: space-between;
width: 100%;
padding: 10px 0;
border-bottom: 2px solid var(--neutral-700);
font-weight: bold;
margin-bottom: 15px;
color: var(--neutral-300);
}
#pastes {
list-style-type: none;
width: 100%;
max-height: 90%;
overflow-y: auto;
padding: 0;
border-radius: 4px;
scrollbar-width: thin;
scrollbar-color: var(--neutral-700) var(--neutral-900);
border: none;
}
#pastes li {
margin: 0.75rem 0;
transition: transform 0.2s ease;
}
#pastes li:hover {
transform: translateY(-2px);
}
#pastes li a {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
gap: 0.5rem;
padding: 0.5rem 0.75rem;
background-color: var(--neutral-800);
color: var(--neutral-50);
text-decoration: none;
transition: all 0.3s ease;
border-radius: 6px;
border: 1px solid var(--neutral-700);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
#pastes li a:hover {
background-color: var(--neutral-750);
border-color: var(--neutral-600);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
#pastes li a p {
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#paste-title {
font-weight: 500;
color: var(--neutral-100);
}
#paste-date {
color: var(--neutral-300);
font-size: 0.9rem;
text-align: center;
}
#paste-syntax {
color: var(--neutral-300);
font-size: 0.9rem;
text-align: right;
}
@media (max-width: 768px) {
#pastes li a {
grid-template-columns: 3fr 2fr;
}
#paste-syntax {
display: none;
}
}
@media (max-width: 576px) {
#pastes li a {
padding: 0.7rem 0.8rem;
}
}
.paste-actions {
display: flex;
justify-content: center;
align-items: center;
margin-top: auto;
padding-top: 15px;
border-top: 1px solid var(--neutral-800);
}
.paste-actions button {
background-color: var(--neutral-700);
color: var(--neutral-50);
border: none;
border-radius: 6px;
padding: 8px 15px;
margin: 0 10px;
cursor: pointer;
transition: all 0.2s ease;
font-weight: 500;
}
.paste-actions button:hover {
background-color: var(--neutral-600);
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.paste-actions button:active {
transform: translateY(0);
}
.paste-actions button:disabled {
background-color: var(--neutral-800);
color: var(--neutral-500);
cursor: not-allowed;
opacity: 0.7;
box-shadow: none;
transform: none;
}
#paste-pages {
margin: 0 15px;
font-weight: bold;
min-width: 40px;
text-align: center;
color: var(--neutral-300);
}
#pastes::-webkit-scrollbar {
width: 8px;
}
#pastes::-webkit-scrollbar-track {
background: var(--neutral-900);
border-radius: 6px;
}
#pastes::-webkit-scrollbar-thumb {
background-color: var(--neutral-700);
border-radius: 6px;
}
#pastes::-webkit-scrollbar-thumb:hover {
background-color: var(--neutral-600);
}
@media (max-width: 992px) {
.main-container {
padding: 15px;
}
.account-info, .paste-list {
padding: 20px;
}
}
@media (max-width: 768px) {
.main-container {
flex-direction: column;
gap: 20px;
}
.account-info, .paste-list {
width: 100%;
}
}
@media (max-width: 576px) {
.main-container {
padding: 10px;
}
.account-info, .paste-list {
padding: 15px;
}
.account-info h1, .paste-list h1 {
font-size: 1.5rem;
}
#pastes li {
flex-direction: column;
align-items: flex-start;
}
#pastes li span {
margin-top: 5px;
font-size: 0.8rem;
}
}
.logout-modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 2000;
}
.logout-modal-box {
background: var(--neutral-900);
color: var(--neutral-100);
padding: 2rem 2.5rem;
border-radius: 10px;
box-shadow: 0 8px 32px rgba(0,0,0,0.25);
text-align: center;
min-width: 300px;
max-width: 90vw;
}
.logout-modal-box h2 {
margin-bottom: 1rem;
font-size: 1.4rem;
color: var(--neutral-50);
}
.logout-modal-box p {
margin-bottom: 2rem;
color: var(--neutral-300);
}
.logout-modal-box button {
margin: 0 0.5rem;
padding: 0.7rem 1.5rem;
border-radius: 6px;
font-weight: 600;
border: none;
cursor: pointer;
font-size: 1rem;
transition: background 0.2s, color 0.2s;
}
#confirm-logout {
background: #e74c3c;
color: #fff;
}
#confirm-logout:hover {
background: #c0392b;
}
#cancel-logout {
background: var(--neutral-700);
color: #fff;
}
#cancel-logout:hover {
background: var(--neutral-600);
}
#logout-button {
background-color: var(--neutral-700);
color: var(--neutral-50);
border: none;
border-radius: 6px;
padding: 10px 24px;
margin-top: auto;
font-size: 1.08rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
letter-spacing: 0.5px;
}
#logout-button:hover {
background-color: var(--neutral-600);
color: var(--neutral-10);
transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0,0,0,0.13);
}
#logout-button:active {
background-color: var(--neutral-800);
color: var(--neutral-200);
transform: none;
box-shadow: none;
}
#delete-account-button {
background-color: #e74c3c;
color: #fff;
border: none;
border-radius: 6px;
padding: 10px 24px;
font-size: 1.08rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
letter-spacing: 0.5px;
margin-top: 10px;
}
#delete-account-button:hover {
background-color: #c0392b;
color: #fff;
transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0,0,0,0.13);
}
#delete-account-button:active {
background-color: #a93226;
color: #fff;
transform: none;
box-shadow: none;
}
.delete-modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 2100;
}
.delete-modal-box {
background: var(--neutral-900);
color: var(--neutral-100);
padding: 2rem 2.5rem;
border-radius: 10px;
box-shadow: 0 8px 32px rgba(0,0,0,0.25);
text-align: center;
min-width: 320px;
max-width: 95vw;
}
.delete-modal-box h2 {
margin-bottom: 1rem;
font-size: 1.4rem;
color: #e74c3c;
}
.delete-modal-box p {
margin-bottom: 1.2rem;
color: var(--neutral-300);
}
.delete-modal-box input {
margin-bottom: 0.7rem;
width: 90%;
padding: 8px;
border-radius: 5px;
border: 1px solid var(--neutral-700);
background: var(--neutral-800);
color: var(--neutral-100);
font-size: 1rem;
outline: none;
transition: border 0.2s;
}
.delete-modal-box input:focus {
border: 1.5px solid #e74c3c;
}
.delete-modal-box button {
margin: 0 0.5rem;
padding: 0.7rem 1.5rem;
border-radius: 6px;
font-weight: 600;
border: none;
cursor: pointer;
font-size: 1rem;
transition: background 0.2s, color 0.2s;
}
#confirm-delete-account {
background: #e74c3c;
color: #fff;
}
#confirm-delete-account:hover {
background: #c0392b;
}
#confirm-delete-account:disabled {
background: var(--neutral-800);
color: var(--neutral-500);
cursor: not-allowed;
opacity: 0.7;
box-shadow: none;
transform: none;
}
#cancel-delete-account {
background: var(--neutral-700);
color: #fff;
}
#cancel-delete-account:hover {
background: var(--neutral-600);
}
#delete-error {
color: #e74c3c;
font-size: 1rem;
margin-top: 1rem;
}
+114 -64
View File
@@ -2,101 +2,151 @@
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding: 1rem 2rem; padding: 0.75rem 2rem;
background-color: var(--neutral-900); background-color: var(--neutral-900);
color: #fff; color: #fff;
position: fixed; position: fixed;
width: 100%; width: 100%;
top: 0; top: 0;
left: 0; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
right: 0; z-index: 1000;
} }
.nav-link {
.nav-brand {
flex: 0 0 auto;
z-index: 15;
}
.brand-link {
font-size: 1.5rem;
font-weight: 700;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
font-size: 1.2rem; letter-spacing: 0.5px;
transition: color 0.3s; transition: transform 0.2s ease;
}
.nav-link:hover {
color: var(--neutral-300);
} }
.nav-links .nav-link { .brand-link:hover {
width: auto; transform: scale(1.05);
padding: 0 1rem;
border-bottom: none;
} }
.nav-links .nav-link:last-child { .nav-center {
border-bottom: none; position: absolute;
} left: 0;
right: 0;
.hamburger { display: flex;
display: none; justify-content: center;
background: none; align-items: center;
border: none;
font-size: 2rem;
cursor: pointer;
margin: 0 auto;
} }
.nav-links { .nav-links {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
position: static; align-items: center;
background-color: transparent; justify-content: center;
padding: 0; gap: 1rem;
max-height: none;
transition: none;
} }
.nav-links.show { .nav-link {
display: flex; color: rgba(255, 255, 255, 0.85);
text-decoration: none;
font-size: 1.1rem;
padding: 0.6rem 1.2rem;
border-radius: 6px;
transition: all 0.3s ease;
font-weight: 500;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.nav-link:hover {
color: #fff;
background-color: rgba(255, 255, 255, 0.1);
transform: translateY(-2px);
}
#nav-bar-selected {
color: #fff;
background-color: rgba(255, 255, 255, 0.15);
font-weight: 500;
}
.hamburger {
display: none;
flex-direction: column; flex-direction: column;
position: absolute; justify-content: space-between;
top: 100%; width: 30px;
left: 0; height: 21px;
right: 0; background: transparent;
background-color: var(--neutral-900); border: none;
padding: 1rem 2rem; cursor: pointer;
max-height: 500px; padding: 0;
transition: max-height 0.3s ease-out; z-index: 15;
overflow: hidden; }
.hamburger-line {
display: block;
height: 3px;
width: 100%;
border-radius: 10px;
background: #fff;
transition: all 0.3s ease;
} }
@media (max-width: 800px) { @media (max-width: 800px) {
.nav-center {
position: static;
}
.nav-links { .nav-links {
display: none; position: fixed;
flex-direction: column; top: 60px;
width: 100%;
position: absolute;
top: 100%;
left: 0; left: 0;
right: 0; right: 0;
border-top: 1px solid var(--neutral-800);
background-color: var(--neutral-900); background-color: var(--neutral-900);
padding: 1rem 2rem;
max-height: 0;
transition: max-height 0.3s ease-out;
overflow: hidden;
}
.nav-link{
width: 100% !important;
padding: 1rem 0 !important;
text-align: center;
border-bottom: 1px solid var(--neutral-800) !important;
}
.nav-links.show {
display: flex;
max-height: 500px;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
padding: 0;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out, padding 0.3s ease;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
} }
.nav-links.show {
max-height: 300px;
padding: 1rem 0;
}
.nav-link {
width: 90%;
text-align: center;
padding: 1rem;
border-bottom: 1px solid var(--neutral-800);
}
.home-link {
border: none;
border-bottom: 1px solid var(--neutral-800);
order: -1;
}
.nav-link:last-child {
border-bottom: none;
}
.hamburger { .hamburger {
display: block; display: flex;
margin: 0 auto;
} }
.nav-bar {
justify-content: center; .hamburger.active .hamburger-line:nth-child(1) {
transform: translateY(9px) rotate(45deg);
}
.hamburger.active .hamburger-line:nth-child(2) {
opacity: 0;
}
.hamburger.active .hamburger-line:nth-child(3) {
transform: translateY(-9px) rotate(-45deg);
} }
} }
+15 -3
View File
@@ -112,9 +112,6 @@ pre code.hljs {
code.hljs { code.hljs {
padding: 3px 5px padding: 3px 5px
} }
/*
SLIGHTLY MODIFIED GITHUB DARK THEME
*/
.hljs { .hljs {
color: #c9d1d9; color: #c9d1d9;
background: var(--neutral-900); background: var(--neutral-900);
@@ -206,3 +203,18 @@ SLIGHTLY MODIFIED GITHUB DARK THEME
color: #ffdcd7; color: #ffdcd7;
background-color: #67060c background-color: #67060c
} }
.throbber {
border: 4px solid var(--neutral-700);
border-top: 4px solid var(--neutral-50);
border-radius: 50%;
width: 24px;
height: 24px;
animation: spin 1s linear infinite;
margin: auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
-1
View File
@@ -7,7 +7,6 @@
} }
:root { :root {
/* TailwindCSS Neutral Colors */
--neutral-50: #fafafa; --neutral-50: #fafafa;
--neutral-100: #f5f5f5; --neutral-100: #f5f5f5;
--neutral-200: #e5e5e5; --neutral-200: #e5e5e5;
+52
View File
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Sharpbin</title>
<link rel="preload" href="css/style.css" as="style">
<link rel="preload" href="css/dash.css" as="style">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/dash.css">
<link rel="preload" href="js/dash.js" as="script">
<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:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Mono:wght@100..900&display=swap"
rel="stylesheet">
</head>
<body>
<div class="main-container">
<div class="account-info">
<h1 id="account-header">Account Information</h1>
<p id="account-username">Username: </p>
<p id="account-email">Email: </p>
<p id="account-joindate">Joined: </p>
<p id="account-lastlogin">Last Login: </p>
<p id="account-pastes">Pastes: </p>
<button id="logout-button" onclick="logout()">Logout</button>
<button id="delete-account-button" onclick="deleteAccount()">Delete Account</button>
</div>
<div class="paste-list">
<h1 id="paste-header">Your Pastes</h1>
<div class="paste-information">
<p id="paste-title">Title</p>
<p id="paste-date">Date</p>
<p id="paste-syntax">Syntax</p>
</div>
<ol class="pastes" id="pastes">
</ol>
<div class="paste-actions">
<button id="previous-button" onclick="previousPage()">&lt;</button>
<p id="paste-pages">0/0</p>
<button id="next-button" onclick="nextPage()">></button>
</div>
</div>
</div>
</body>
<script src="js/dash.js"></script>
<script src="js/navbar.js"></script>
</html>
+1 -1
View File
@@ -18,7 +18,7 @@
<body> <body>
<div class="main-container"> <div class="main-container">
<form class="create-form" id="create-form"> <form class="create-form" id="create-form">
<input type="text" name="title" id="title" placeholder="Title"> <input type="text" name="title" id="title" placeholder="Title" maxlength="500">
<textarea name="content" id="content" placeholder="Content"></textarea> <textarea name="content" id="content" placeholder="Content"></textarea>
<label style="margin-bottom: -2.3rem; margin-top: 1.1rem; z-index: 2; align-self: flex-start; margin-left: 1rem; pointer-events: none;">Syntax Highlighting -</label> <label style="margin-bottom: -2.3rem; margin-top: 1.1rem; z-index: 2; align-self: flex-start; margin-left: 1rem; pointer-events: none;">Syntax Highlighting -</label>
<select name="syntax" id="syntax"> <select name="syntax" id="syntax">
+55 -29
View File
@@ -1,50 +1,74 @@
pages = 0; let pages = 0;
let currentPage = 0;
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
var queries = new URLSearchParams(window.location.search); const queries = new URLSearchParams(window.location.search);
var page = queries.get("page"); let page = parseInt(queries.get("page"));
var limit = queries.get("limit"); let limit = parseInt(queries.get("limit"));
if (parseInt(page).isNaN) { if (isNaN(page)) {
page = 0; page = 0;
} }
var archiveList = document.getElementById("archives"); if (page < 0) {
var archiveListHTML = "";
var pagesElement = document.getElementById("paste-pages");
if (page == null || page < 0) {
page = 0; page = 0;
} }
if (limit == null || limit < 1 || limit > 25) {
if (isNaN(limit) || limit < 1 || limit > 25) {
limit = 25; limit = 25;
} }
var archiveData = await getPastes(page, limit); currentPage = page;
var pastes = archiveData.pastes; 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; pages = archiveData.pages;
pagesElement.innerText = `${parseInt(page) + 1}/${pages + 1}`;
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;
}
let archiveListHTML = "";
pastes.forEach(paste => { pastes.forEach(paste => {
var title = paste.title.length > 30 ? paste.title.substring(0, 30) + '...' : paste.title; const title = paste.title.length > 30 ? paste.title.substring(0, 30) + '...' : paste.title;
archiveListHTML += ` archiveListHTML += `
<li> <li>
<a href="/${paste.id}"> <a href="/${paste.id}">
<p id="archive-title" title="${paste.title}">${title}</p> <p id="archive-title" title="${paste.title}">${title}</p>
<p id="archive-date">${formatDate(paste.created)}</p> <p id="archive-date">${formatDate(paste.created)}</p>
<p id="archive-syntax">${paste.syntax}</p> <p id="archive-syntax">${paste.syntax || 'Plain Text'}</p>
</a> </a>
</li> </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) { async function getPastes(page, limit) {
const response = await fetch(`/api/pastes/archive?page=${page}&limit=${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(); const data = await response.json();
return data; return data;
} }
@@ -53,8 +77,8 @@ function formatDate(unix) {
if (typeof unix !== 'number' || isNaN(unix)) { if (typeof unix !== 'number' || isNaN(unix)) {
return 'Invalid date'; return 'Invalid date';
} }
var nowunix = Math.floor(Date.now() / 1000); const nowunix = Math.floor(Date.now() / 1000);
var diff = nowunix - unix; const diff = nowunix - unix;
if (diff < 60) { if (diff < 60) {
return `${diff} second${diff !== 1 ? 's' : ''} ago`; return `${diff} second${diff !== 1 ? 's' : ''} ago`;
@@ -71,14 +95,15 @@ function formatDate(unix) {
} }
function nextPage() { function nextPage() {
var queries = new URLSearchParams(window.location.search); const queries = new URLSearchParams(window.location.search);
var page = queries.get("page"); let page = parseInt(queries.get("page"));
var limit = queries.get("limit"); let limit = parseInt(queries.get("limit"));
if (page == null || page < 0) { if (isNaN(page) || page < 0) {
page = 0; page = 0;
} }
if (limit == null || limit < 1 || limit > 25) {
if (isNaN(limit) || limit < 1 || limit > 25) {
limit = 25; limit = 25;
} }
@@ -91,18 +116,19 @@ function nextPage() {
} }
function previousPage() { function previousPage() {
var queries = new URLSearchParams(window.location.search); const queries = new URLSearchParams(window.location.search);
var page = queries.get("page"); let page = parseInt(queries.get("page"));
var limit = queries.get("limit"); let limit = parseInt(queries.get("limit"));
if (page == null || page < 0) { if (isNaN(page) || page < 0) {
page = 0; page = 0;
} }
if (limit == null || limit < 1 || limit > 25) {
if (isNaN(limit) || limit < 1 || limit > 25) {
limit = 25; limit = 25;
} }
if (page < pages) { if (page <= 0) {
return; return;
} }
+271
View File
@@ -0,0 +1,271 @@
let currentPage = 1;
let totalPages = 0;
let pastesPerPage = 10;
let userPastes = [];
document.addEventListener('DOMContentLoaded', function () {
fetchAccountInfo();
fetchUserPastes();
});
async function fetchAccountInfo() {
try {
const response = await fetch('/api/accounts/authorized');
const accountData = await response.json();
if (accountData.success === false) {
window.location.href = '/login';
}
updateAccountInfo(accountData.user);
} catch (error) {
console.error('Error fetching account information:', error);
if (error.message.includes('401')) {
window.location.href = '/login.html';
}
}
}
function updateAccountInfo(data) {
document.getElementById('account-username').textContent = `Username: ${data.username}`;
document.getElementById('account-email').textContent = `Email: ${data.email || 'Not provided'}`;
if (data.displayname) {
const usernameElement = document.getElementById('account-header');
usernameElement.textContent = data.displayname;
}
const createdDate = new Date(data.created * 1000);
const lastLoginDate = new Date(data.lastLogin * 1000);
document.getElementById('account-joindate').textContent = `Joined: ${formatDate(createdDate)}`;
document.getElementById('account-lastlogin').textContent = `Last Login: ${formatDate(lastLoginDate)}`;
}
function formatDate(date) {
if (isNaN(date.getTime())) {
return 'Never';
}
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
}
function getRelativeTime(date) {
const now = new Date();
const diff = now - date;
const seconds = Math.floor(diff / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
if (isNaN(date.getTime())) return '';
if (seconds < 60) return 'just now';
if (minutes < 60) return `${minutes} min ago`;
if (hours < 24) return `${hours} hr${hours > 1 ? 's' : ''} ago`;
if (days < 7) return `${days} day${days > 1 ? 's' : ''} ago`;
return date.toLocaleDateString();
}
async function fetchUserPastes() {
try {
const response = await fetch('/api/pastes/my?page=0&limit=15');
const pastesData = await response.json();
if (pastesData.message === 'No pastes found.' || pastesData.message === 'Page out of range.') {
userPastes = [];
document.getElementById('account-pastes').textContent = `Pastes: 0`;
totalPages = 0;
document.getElementById('paste-pages').textContent = `0/0`;
displayPastes();
return;
}
userPastes = pastesData.pastes;
document.getElementById('account-pastes').textContent = `Pastes: ${userPastes.length}`;
totalPages = Math.ceil(userPastes.length / pastesPerPage);
document.getElementById('paste-pages').textContent = `${currentPage}/${totalPages || 1}`;
displayPastes();
} catch (error) {
console.error('Error fetching user pastes:', error);
}
}
function displayPastes() {
const pastesList = document.getElementById('pastes');
pastesList.innerHTML = '';
const pasteInfoHeader = document.querySelector('.paste-information');
const pasteActions = document.querySelector('.paste-actions');
const prevButton = document.getElementById('previous-button');
const nextButton = document.getElementById('next-button');
if (userPastes.length === 0) {
if (pasteInfoHeader) pasteInfoHeader.style.display = 'none';
if (pasteActions) pasteActions.style.display = 'none';
if (prevButton) prevButton.disabled = true;
if (nextButton) nextButton.disabled = true;
const noItems = document.createElement('li');
noItems.textContent = 'No pastes found';
pastesList.appendChild(noItems);
return;
} else {
if (pasteInfoHeader) pasteInfoHeader.style.display = '';
if (pasteActions) pasteActions.style.display = '';
}
if (prevButton) prevButton.disabled = currentPage <= 1;
if (nextButton) nextButton.disabled = currentPage >= totalPages || totalPages <= 1;
const startIndex = (currentPage - 1) * pastesPerPage;
const endIndex = Math.min(startIndex + pastesPerPage, userPastes.length);
for (let i = startIndex; i < endIndex; i++) {
const paste = userPastes[i];
const pasteItem = document.createElement('li');
const pasteLink = document.createElement('a');
pasteLink.href = `/paste/${paste.id}`;
pasteLink.style.display = 'grid';
pasteLink.style.gridTemplateColumns = '2fr 1fr 1fr';
pasteLink.style.gap = '1rem';
const titleP = document.createElement('p');
titleP.id = 'paste-title';
titleP.textContent = paste.title || 'Untitled';
const dateP = document.createElement('p');
dateP.id = 'paste-date';
const createdDate = new Date(paste.created * 1000);
dateP.textContent = `${formatDate(createdDate)} (${getRelativeTime(createdDate)})`;
const syntaxP = document.createElement('p');
syntaxP.id = 'paste-syntax';
syntaxP.textContent = paste.syntax || 'plaintext';
pasteLink.appendChild(titleP);
pasteLink.appendChild(dateP);
pasteLink.appendChild(syntaxP);
pasteItem.appendChild(pasteLink);
pastesList.appendChild(pasteItem);
}
}
function previousPage() {
if (currentPage > 1) {
currentPage--;
document.getElementById('paste-pages').textContent = `${currentPage}/${totalPages || 1}`;
displayPastes();
}
}
function nextPage() {
if (currentPage < totalPages) {
currentPage++;
document.getElementById('paste-pages').textContent = `${currentPage}/${totalPages || 1}`;
displayPastes();
}
}
function logout() {
if (document.querySelector('.logout-modal-overlay')) return;
const modalOverlay = document.createElement('div');
modalOverlay.className = 'logout-modal-overlay';
const modalBox = document.createElement('div');
modalBox.className = 'logout-modal-box';
modalBox.innerHTML = `
<h2>Confirm Logout</h2>
<p>Are you sure you want to log out?</p>
<button id="confirm-logout">Logout</button>
<button id="cancel-logout">Cancel</button>
`;
modalOverlay.appendChild(modalBox);
document.body.appendChild(modalOverlay);
document.getElementById('cancel-logout').onclick = function () {
document.body.removeChild(modalOverlay);
};
document.getElementById('confirm-logout').onclick = async function () {
try {
await fetch('/api/accounts/logout', { method: 'POST', credentials: 'include' });
} catch { }
window.location.href = '/login';
};
}
function deleteAccount() {
if (document.querySelector('.delete-modal-overlay')) return;
const username = document.getElementById('account-username').textContent.replace('Username: ', '').trim();
const pasteCount = userPastes.length;
const modalOverlay = document.createElement('div');
modalOverlay.className = 'delete-modal-overlay';
const modalBox = document.createElement('div');
modalBox.className = 'delete-modal-box';
modalBox.innerHTML = `
<h2>Delete Account</h2>
<p>This action is <b>irreversible</b> and will delete your account and all your ${pasteCount} pastes.</p>
<p>Type your username <b>${username}</b> and your paste count <b>${pasteCount}</b> to confirm:</p>
<input id="delete-username" type="text" placeholder="Username" style="margin-bottom:8px;width:90%;padding:8px;border-radius:5px;border:1px solid var(--neutral-700);background:var(--neutral-800);color:var(--neutral-100);"><br>
<input id="delete-pastecount" type="number" placeholder="Paste count" style="margin-bottom:16px;width:90%;padding:8px;border-radius:5px;border:1px solid var(--neutral-700);background:var(--neutral-800);color:var(--neutral-100);"><br>
<button id="confirm-delete-account" disabled>Delete</button>
<button id="cancel-delete-account">Cancel</button>
<p id="delete-error" style="color:#e74c3c;margin-top:1rem;display:none;"></p>
`;
modalOverlay.appendChild(modalBox);
document.body.appendChild(modalOverlay);
document.getElementById('cancel-delete-account').onclick = function () {
document.body.removeChild(modalOverlay);
};
const userInput = document.getElementById('delete-username');
const countInput = document.getElementById('delete-pastecount');
const confirmBtn = document.getElementById('confirm-delete-account');
function validateInputs() {
if (userInput.value.trim() === username && countInput.value.trim() === String(pasteCount)) {
confirmBtn.disabled = false;
} else {
confirmBtn.disabled = true;
}
}
userInput.addEventListener('input', validateInputs);
countInput.addEventListener('input', validateInputs);
confirmBtn.onclick = async function () {
if (confirmBtn.disabled) return;
try {
await fetch('/api/accounts/delete', { method: 'POST', credentials: 'include' });
} catch { }
window.location.href = '/register';
};
}
+89
View File
@@ -0,0 +1,89 @@
document.addEventListener('DOMContentLoaded', function () {
const loginForm = document.getElementById('login-form');
const errorMessage = document.getElementById('error-message');
checkAuthStatus();
loginForm.addEventListener('submit', async function (event) {
event.preventDefault();
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
if (!username || !password) {
showError('Please fill in all required fields');
return;
}
try {
const submitButton = loginForm.querySelector('button[type="submit"]');
const originalButtonText = submitButton.textContent;
submitButton.disabled = true;
submitButton.textContent = 'Logging in...';
const isEmail = username.includes('@');
const requestData = isEmail
? { email: username, password: password }
: { username: username, password: password };
const response = await fetch('/api/accounts/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
const data = await response.json();
if (data.success) {
window.location.href = '/dash';
} else {
showError(data.message || 'Login failed. Please check your credentials.');
submitButton.disabled = false;
submitButton.textContent = originalButtonText;
}
} catch (error) {
console.error('Login error:', error);
showError('An unexpected error occurred. Please try again later.');
const submitButton = loginForm.querySelector('button[type="submit"]');
submitButton.disabled = false;
submitButton.textContent = 'Login';
}
});
function showError(message) {
errorMessage.textContent = message;
errorMessage.classList.add('visible');
setTimeout(() => {
errorMessage.classList.remove('visible');
}, 5000);
}
async function checkAuthStatus() {
try {
const response = await fetch('/api/accounts/authorized');
const data = await response.json();
if (data.success) {
window.location.href = '/dash';
}
} catch (error) {
console.log('Not logged in');
}
}
});
+199 -7
View File
@@ -1,22 +1,214 @@
const navbarHTML = ` const navbarHTML = `
<div class="nav-bar"> <div class="nav-bar">
<button class="hamburger" onclick="toggleMenu()">☰</button> <div class="nav-brand">
<div class="nav-links"> <a href="/" class="brand-link">Sharpbin</a>
<a href="/" class="nav-link">Home</a>
<a href="/archive" class="nav-link">Paste Archive</a>
</div> </div>
<div class="nav-center">
<div class="nav-links">
<a href="/archive" class="nav-link">Archives</a>
<a href="/" class="nav-link home-link">Home</a>
<a href="#" class="nav-link">Account</a>
</div>
</div>
<button class="hamburger" onclick="toggleMenu()" aria-label="Toggle menu">
<span class="hamburger-line"></span>
<span class="hamburger-line"></span>
<span class="hamburger-line"></span>
</button>
<style> <style>
.nav-bar {display: flex;justify-content: space-between;align-items: center;padding: 1rem 2rem;background-color: var(--neutral-900);color: #fff;position: fixed;width: 100%;top: 0;left: 0;right: 0;}.nav-link {color: #fff;text-decoration: none;font-size: 1.2rem;transition: color 0.3s;}.nav-link:hover {color: var(--neutral-300);}.nav-links .nav-link {width: auto;padding: 0 1rem;border-bottom: none;}.nav-links .nav-link:last-child {border-bottom: none;}.hamburger {display: none;background: none;border: none;font-size: 2rem;cursor: pointer;margin: 0 auto;}.nav-links {display: flex;flex-direction: row;position: static;background-color: transparent;padding: 0;max-height: none;transition: none;}.nav-links.show {display: flex;flex-direction: column;position: absolute;top: 100%;left: 0;right: 0;background-color: var(--neutral-900);padding: 1rem 2rem;max-height: 500px;transition: max-height 0.3s ease-out;overflow: hidden;}@media (max-width: 800px) {.nav-links {display: none;flex-direction: column;width: 100%;position: absolute;top: 100%;left: 0;right: 0;border-top: 1px solid var(--neutral-800);background-color: var(--neutral-900);padding: 1rem 2rem;max-height: 0;transition: max-height 0.3s ease-out;overflow: hidden;}.nav-link{width: 100% !important;padding: 1rem 0 !important;text-align: center;border-bottom: 1px solid var(--neutral-800) !important;}.nav-links.show {display: flex;max-height: 500px;flex-direction: column;align-items: center;}.hamburger {display: block;margin: 0 auto;}.nav-bar {justify-content: center;}} .nav-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem 2rem;
background-color: var(--neutral-900);
color: #fff;
position: fixed;
width: 100%;
top: 0;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
z-index: 1000;
}
.nav-brand {
flex: 0 0 auto;
z-index: 15;
}
.brand-link {
font-size: 1.5rem;
font-weight: 700;
color: #fff;
text-decoration: none;
letter-spacing: 0.5px;
transition: transform 0.2s ease;
}
.brand-link:hover {
transform: scale(1.05);
}
.nav-center {
position: absolute;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
}
.nav-links {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 1rem;
}
.nav-link {
color: rgba(255, 255, 255, 0.85);
text-decoration: none;
font-size: 1.1rem;
padding: 0.6rem 1.2rem;
border-radius: 6px;
transition: all 0.3s ease;
font-weight: 500;
text-align: center;
border: 1px solid rgba(255, 255, 255, 0.2);
max-width: 125px;
width: 125px;
}
.nav-link:hover {
color: #fff;
background-color: rgba(255, 255, 255, 0.1);
transform: translateY(-2px);
}
#nav-bar-selected {
color: #fff;
background-color: rgba(255, 255, 255, 0.15);
font-weight: 500;
}
.hamburger {
display: none;
flex-direction: column;
justify-content: space-between;
width: 30px;
height: 21px;
background: transparent;
border: none;
cursor: pointer;
padding: 0;
z-index: 15;
}
.hamburger-line {
display: block;
height: 3px;
width: 100%;
border-radius: 10px;
background: #fff;
transition: all 0.3s ease;
}
@media (max-width: 800px) {
.nav-center {
position: static;
}
.nav-links {
position: fixed;
top: 60px;
left: 0;
right: 0;
background-color: var(--neutral-900);
flex-direction: column;
align-items: center;
padding: 0;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out, padding 0.3s ease;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
.nav-links.show {
max-height: 300px;
padding: 1rem 0;
}
.nav-link {
width: 90%;
text-align: center;
padding: 1rem;
border-bottom: 1px solid var(--neutral-800);
}
.home-link {
border: none;
border-bottom: 1px solid var(--neutral-800);
order: -1;
}
.nav-link:last-child {
border-bottom: none;
}
.hamburger {
display: flex;
}
.hamburger.active .hamburger-line:nth-child(1) {
transform: translateY(9px) rotate(45deg);
}
.hamburger.active .hamburger-line:nth-child(2) {
opacity: 0;
}
.hamburger.active .hamburger-line:nth-child(3) {
transform: translateY(-9px) rotate(-45deg);
}
}
</style> </style>
</div> </div>
`; `;
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', async () => {
document.body.insertAdjacentHTML('afterbegin', navbarHTML); document.body.insertAdjacentHTML('afterbegin', navbarHTML);
var path = window.location.pathname;
var links = document.querySelectorAll('.nav-link');
let accountHref = '/login';
try {
const resp = await fetch('/api/accounts/authorized');
const data = await resp.json();
if (data && data.success !== false) {
accountHref = '/dash';
}
} catch {}
const accountLink = document.querySelector('.nav-link[href="#"]');
if (accountLink) {
accountLink.setAttribute('href', accountHref);
}
links.forEach(link => {
const href = link.getAttribute('href');
if (href === path) {
link.id = 'nav-bar-selected';
}
if ((path === '/dash' || path === '/login' || path === '/register') && (href === '/dash' || href === '/login')) {
link.id = 'nav-bar-selected';
}
});
}); });
window.toggleMenu = function () { window.toggleMenu = function () {
const nav = document.querySelector('.nav-links'); const nav = document.querySelector('.nav-links');
const hamburger = document.querySelector('.hamburger');
nav.classList.toggle('show'); nav.classList.toggle('show');
hamburger.classList.toggle('active');
}; };
+8 -23
View File
@@ -2,17 +2,19 @@ const visibility = [{ id: 0, name: "Public" }, { id: 1, name: "Unlisted" }, { id
document.addEventListener("DOMContentLoaded", async function () { document.addEventListener("DOMContentLoaded", async function () {
const id = window.location.pathname.split("/")[1]; const id = window.location.pathname.split("/")[1];
const content = await (await fetch(`/api/pastes/${id}`)).text(); const contentPromise = fetch(`/api/pastes/${id}`).then(response => response.text());
const info = await (await fetch(`/api/pastes/${id}/info`)).json(); const infoPromise = fetch(`/api/pastes/${id}/info`).then(response => response.json());
const paste = info.paste;
const blur = document.createElement("div"); const blur = document.createElement("div");
blur.id = "blur"; blur.id = "blur";
blur.dataset.decrypted = "false"; blur.dataset.decrypted = "false";
document.body.appendChild(blur); document.body.appendChild(blur);
const blur2 = document.getElementById("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"); const password = prompt("Enter the password");
try { try {
const decrypted = await decryptAES(content, password); const decrypted = await decryptAES(content, password);
@@ -21,26 +23,23 @@ document.addEventListener("DOMContentLoaded", async function () {
} catch (error) { } catch (error) {
alert("Failed to decrypt, invalid password, or invalid data."); alert("Failed to decrypt, invalid password, or invalid data.");
} }
} else { } else {
blur2.dataset.decrypted = "true"; blur2.dataset.decrypted = "true";
addContent(content, paste.syntax); addContent(content, paste.syntax);
} }
document.title = `${paste.title} - Sharpbin`; document.title = `${paste.title} - Sharpbin`;
addInfo(paste); addInfo(paste);
}); });
function addInfo(paste) { function addInfo(paste) {
document.getElementById("paste-title").innerText = paste.title; document.getElementById("paste-title").innerText = paste.title;
document.getElementById("paste-date").innerText = convertUnixToLocal(paste.created); document.getElementById("paste-date").innerText = convertUnixToLocal(paste.created);
document.getElementById("paste-syntax").innerText = paste.syntax === "none" ? "" : paste.syntax || ""; document.getElementById("paste-syntax").innerText = paste.syntax === "none" ? "" : paste.syntax || "";
document.getElementById("info-throbber").style.display = "none";
document.getElementById("copy-button").addEventListener("click", function () { document.getElementById("copy-button").addEventListener("click", function () {
navigator.clipboard.writeText(window.location.href); navigator.clipboard.writeText(window.location.href);
}); });
document.getElementById("download-button").addEventListener("click", function () { document.getElementById("download-button").addEventListener("click", function () {
if (paste.visibility === 2) {
const content = document.getElementById("paste-content").innerText; const content = document.getElementById("paste-content").innerText;
const blob = new Blob([content], { type: "text/plain" }); const blob = new Blob([content], { type: "text/plain" });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
@@ -51,23 +50,10 @@ function addInfo(paste) {
a.click(); a.click();
document.body.removeChild(a); document.body.removeChild(a);
URL.revokeObjectURL(url); 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);
}
}); });
document.getElementById("raw-button").addEventListener("click", function () { document.getElementById("raw-button").addEventListener("click", function () {
window.location.href = `/raw/${paste.id}`; window.location.href = `/raw/${paste.id}`;
}); });
} }
function addContent(content, syntax) { function addContent(content, syntax) {
@@ -80,11 +66,10 @@ function addContent(content, syntax) {
code.id = "paste-content"; code.id = "paste-content";
code.classList.add("language-" + syntax === "plaintext" ? "none" : syntax); code.classList.add("language-" + syntax === "plaintext" ? "none" : syntax);
if (syntax !== "plaintext" && syntax !== "none" && syntax !== "" && syntax !== null) { if (syntax !== "plaintext" && syntax !== "none" && syntax !== "" && syntax !== null) {
console.log(syntax);
hljs.highlightElement(code); hljs.highlightElement(code);
} }
hljs.lineNumbersBlock(code); hljs.lineNumbersBlock(code);
document.getElementById("content-throbber").style.display = "none";
} }
async function decryptAES(content, password) { async function decryptAES(content, password) {
+111
View File
@@ -0,0 +1,111 @@
document.addEventListener('DOMContentLoaded', function() {
const registerForm = document.getElementById('register-form');
const errorMessage = document.getElementById('error-message');
checkAuthStatus();
registerForm.addEventListener('submit', async function(event) {
event.preventDefault();
const username = document.getElementById('username').value.trim();
const email = document.getElementById('email').value.trim();
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirm-password').value;
if (!username || !password) {
showError('Please fill in all required fields');
return;
}
if (password !== confirmPassword) {
showError('Passwords do not match');
return;
}
if (password.length < 6) {
showError('Password must be at least 6 characters long');
return;
}
if (username.length < 3) {
showError('Username must be at least 3 characters long');
return;
}
try {
const submitButton = registerForm.querySelector('button[type="submit"]');
const originalButtonText = submitButton.textContent;
submitButton.disabled = true;
submitButton.textContent = 'Creating account...';
const requestData = {
username: username,
password: password
};
if (email) {
requestData.email = email;
}
const response = await fetch('/api/accounts/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
const data = await response.json();
if (data.success) {
window.location.href = '/dash';
} else {
showError(data.message || 'Registration failed. Please try again.');
submitButton.disabled = false;
submitButton.textContent = originalButtonText;
}
} catch (error) {
console.error('Registration error:', error);
showError('An unexpected error occurred. Please try again later.');
const submitButton = registerForm.querySelector('button[type="submit"]');
submitButton.disabled = false;
submitButton.textContent = 'Register';
}
});
function showError(message) {
errorMessage.textContent = message;
errorMessage.classList.add('visible');
setTimeout(() => {
errorMessage.classList.remove('visible');
}, 5000);
}
async function checkAuthStatus() {
try {
const response = await fetch('/api/accounts/authorized');
const data = await response.json();
if (data.success) {
window.location.href = '/dash';
}
} catch (error) {
console.log('Not logged in');
}
}
});
+44
View File
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - Sharpbin</title>
<link rel="preload" href="css/style.css" as="style">
<link rel="preload" href="css/auth.css" as="style">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/auth.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:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
</head>
<body>
<div class="auth-container">
<div class="auth-form-container">
<h1 class="auth-title">Login to Sharpbin</h1>
<div id="error-message" class="error-message"></div>
<form id="login-form" class="auth-form">
<div class="form-group">
<label for="username">Username or Email</label>
<input type="text" id="username" name="username" placeholder="Enter your username or email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Enter your password" required>
</div>
<button type="submit" class="auth-button">Login</button>
</form>
<div class="auth-links">
<p>Don't have an account? <a href="register.html">Register</a></p>
<p><a href="/">Back to Home</a></p>
</div>
</div>
</div>
<script src="js/login.js"></script>
<script src="js/navbar.js"></script>
</body>
</html>
+2
View File
@@ -23,6 +23,7 @@
<div class="paste-header"> <div class="paste-header">
<h1 id="paste-title">Title</h1> <h1 id="paste-title">Title</h1>
<div class="paste-information"> <div class="paste-information">
<div id="info-throbber" class="throbber"></div>
<p id="paste-syntax">Syntax</p> <p id="paste-syntax">Syntax</p>
<p id="paste-date">Date</p> <p id="paste-date">Date</p>
</div> </div>
@@ -33,6 +34,7 @@
<button id="download-button">Download</button> <button id="download-button">Download</button>
<button id="raw-button">Raw</button> <button id="raw-button">Raw</button>
</div> </div>
<div id="content-throbber" class="throbber"></div>
<pre id="paste-content">Loading...</pre> <pre id="paste-content">Loading...</pre>
</div> </div>
</div> </div>
+52
View File
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - Sharpbin</title>
<link rel="preload" href="css/style.css" as="style">
<link rel="preload" href="css/auth.css" as="style">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/auth.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:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
</head>
<body>
<div class="auth-container">
<div class="auth-form-container">
<h1 class="auth-title">Create an Account</h1>
<div id="error-message" class="error-message"></div>
<form id="register-form" class="auth-form">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Choose a username" required>
</div>
<div class="form-group">
<label for="email">Email (optional)</label>
<input type="email" id="email" name="email" placeholder="Enter your email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Create a password" required>
</div>
<div class="form-group">
<label for="confirm-password">Confirm Password</label>
<input type="password" id="confirm-password" name="confirm-password" placeholder="Confirm your password" required>
</div>
<button type="submit" class="auth-button">Register</button>
</form>
<div class="auth-links">
<p>Already have an account? <a href="login.html">Login</a></p>
<p><a href="/">Back to Home</a></p>
</div>
</div>
</div>
<script src="js/register.js"></script>
<script src="js/navbar.js"></script>
</body>
</html>