mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
User pages added
This commit is contained in:
@@ -374,3 +374,4 @@ PasteBin/p/2d48a001-383d-44fd-8553-4806c9de100d.html
|
||||
*.sqlite-journal
|
||||
/PasteBin/logs.txt
|
||||
/PasteBin/config.json
|
||||
/PasteBin/Encryption.cs
|
||||
|
||||
@@ -596,6 +596,192 @@ class Program
|
||||
return;
|
||||
}
|
||||
}).RequireRateLimiting("fixed-bigger");
|
||||
app.MapGet("/u/{username}", async (HttpContext context) =>
|
||||
{
|
||||
string username = context.Request?.RouteValues?["username"]?.ToString();
|
||||
var html = File.ReadAllText(@"assets\user.html");
|
||||
using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT * FROM users WHERE Username LIKE @Username";
|
||||
command.Parameters.AddWithValue("@Username", username);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
await reader.ReadAsync();
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
html = File.ReadAllText(@"assets\error.html");
|
||||
html = html.Replace("{code}", "404");
|
||||
html = html.Replace("{message}", "User not found");
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.WriteAsync(html);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var user = new User
|
||||
{
|
||||
UID = reader.GetString(0),
|
||||
UUID = reader.GetString(1),
|
||||
Username = reader.GetString(2),
|
||||
PasswordHash = reader.GetString(3),
|
||||
CreationDate = reader.GetString(4),
|
||||
LastLoginDate = reader.GetString(5),
|
||||
Type = reader.GetInt32(6),
|
||||
State = reader.GetInt32(7),
|
||||
};
|
||||
List<Paste> pastes = new List<Paste>();
|
||||
var pastesCommand = connection.CreateCommand();
|
||||
pastesCommand.CommandText = "SELECT * FROM pastes WHERE Uploader LIKE @Uploader ORDER BY UID DESC";
|
||||
pastesCommand.Parameters.AddWithValue("@Uploader", user.UUID);
|
||||
var pastesReader = await pastesCommand.ExecuteReaderAsync();
|
||||
while (await pastesReader.ReadAsync())
|
||||
{
|
||||
var paste = new Paste
|
||||
{
|
||||
Title = pastesReader.GetString(1),
|
||||
UnixDate = long.Parse(pastesReader.GetString(2)),
|
||||
Size = pastesReader.GetString(3),
|
||||
Visibility = pastesReader.GetString(4),
|
||||
Id = pastesReader.GetString(5),
|
||||
};
|
||||
pastes.Add(paste);
|
||||
}
|
||||
string pasteList = string.Empty;
|
||||
long totalSize = 0;
|
||||
foreach (var paste in pastes)
|
||||
{
|
||||
totalSize += long.Parse(paste.Size);
|
||||
var difference = GetTimeDifference(DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0), DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.Now.ToUnixTimeSeconds()));
|
||||
string title = paste.Title;
|
||||
if (title.Length > 20)
|
||||
{
|
||||
title = title.Substring(0, 20) + "...";
|
||||
}
|
||||
pasteList += $"<a class=\"list-a\" href=\"/{paste.Id}\"><li class=\"list-item \">{paste.Title} {difference} {ConvertToBytes(paste.Size)}</li></a>";
|
||||
}
|
||||
html = html.Replace("{username}", user.Username);
|
||||
html = html.Replace("{uid}", user.UID);
|
||||
html = html.Replace("{creationdate}", user.CreationDate);
|
||||
html = html.Replace("{type}", accountType[user.Type]);
|
||||
html = html.Replace("{totalpastes}", pastes.Count.ToString());
|
||||
html = html.Replace("{totalsize}", ConvertToBytes(totalSize.ToString()));
|
||||
html = html.Replace("{pastes}", pasteList);
|
||||
if (await IsLoggedInAsync(context.Request.Cookies["token"]))
|
||||
{
|
||||
var loggedInUser = await GetLoggedInUserAsync(context.Request.Cookies["token"]);
|
||||
if (loggedInUser.UUID == user.UUID)
|
||||
{
|
||||
html = html.Replace("{html}", "<a href=\"/dash\">dashboard</a>");
|
||||
}
|
||||
else
|
||||
{
|
||||
html = html.Replace("{html}", "<a href=\"/dash\">dashboard</a>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
html = html.Replace("{html}", "<a href=\"/login\">login</a> <a href=\"/sign-up\">sign up</a>");
|
||||
}
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.WriteAsync(html);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
app.MapGet("/uid/{uid}", async (HttpContext context) =>
|
||||
{
|
||||
string username = context.Request?.RouteValues?["uid"]?.ToString();
|
||||
var html = File.ReadAllText(@"assets\user.html");
|
||||
using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT * FROM users WHERE UID = @Username";
|
||||
command.Parameters.AddWithValue("@Username", username);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
await reader.ReadAsync();
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
html = File.ReadAllText(@"assets\error.html");
|
||||
html = html.Replace("{code}", "404");
|
||||
html = html.Replace("{message}", "User not found");
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.WriteAsync(html);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var user = new User
|
||||
{
|
||||
UID = reader.GetString(0),
|
||||
UUID = reader.GetString(1),
|
||||
Username = reader.GetString(2),
|
||||
PasswordHash = reader.GetString(3),
|
||||
CreationDate = reader.GetString(4),
|
||||
LastLoginDate = reader.GetString(5),
|
||||
Type = reader.GetInt32(6),
|
||||
State = reader.GetInt32(7),
|
||||
};
|
||||
List<Paste> pastes = new List<Paste>();
|
||||
var pastesCommand = connection.CreateCommand();
|
||||
pastesCommand.CommandText = "SELECT * FROM pastes WHERE Uploader LIKE @Uploader ORDER BY UID DESC";
|
||||
pastesCommand.Parameters.AddWithValue("@Uploader", user.UUID);
|
||||
var pastesReader = await pastesCommand.ExecuteReaderAsync();
|
||||
while (await pastesReader.ReadAsync())
|
||||
{
|
||||
var paste = new Paste
|
||||
{
|
||||
Title = pastesReader.GetString(1),
|
||||
UnixDate = long.Parse(pastesReader.GetString(2)),
|
||||
Size = pastesReader.GetString(3),
|
||||
Visibility = pastesReader.GetString(4),
|
||||
Id = pastesReader.GetString(5),
|
||||
};
|
||||
pastes.Add(paste);
|
||||
}
|
||||
string pasteList = string.Empty;
|
||||
long totalSize = 0;
|
||||
foreach (var paste in pastes)
|
||||
{
|
||||
totalSize += long.Parse(paste.Size);
|
||||
var difference = GetTimeDifference(DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0), DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.Now.ToUnixTimeSeconds()));
|
||||
string title = paste.Title;
|
||||
if (title.Length > 20)
|
||||
{
|
||||
title = title.Substring(0, 20) + "...";
|
||||
}
|
||||
pasteList += $"<a class=\"list-a\" href=\"/{paste.Id}\"><li class=\"list-item \">{paste.Title} {difference} {ConvertToBytes(paste.Size)}</li></a>";
|
||||
}
|
||||
html = html.Replace("{username}", user.Username);
|
||||
html = html.Replace("{uid}", user.UID);
|
||||
html = html.Replace("{creationdate}", user.CreationDate);
|
||||
html = html.Replace("{type}", accountType[user.Type]);
|
||||
html = html.Replace("{totalpastes}", pastes.Count.ToString());
|
||||
html = html.Replace("{totalsize}", ConvertToBytes(totalSize.ToString()));
|
||||
html = html.Replace("{pastes}", pasteList);
|
||||
if (await IsLoggedInAsync(context.Request.Cookies["token"]))
|
||||
{
|
||||
var loggedInUser = await GetLoggedInUserAsync(context.Request.Cookies["token"]);
|
||||
if (loggedInUser.UUID == user.UUID)
|
||||
{
|
||||
html = html.Replace("{html}", "<a href=\"/dash\">dashboard</a>");
|
||||
}
|
||||
else
|
||||
{
|
||||
html = html.Replace("{html}", "<a href=\"/dash\">dashboard</a>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
html = html.Replace("{html}", "<a href=\"/login\">login</a> <a href=\"/sign-up\">sign up</a>");
|
||||
}
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.WriteAsync(html);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#region ADMIN PANEL
|
||||
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>{username}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="account-container">
|
||||
<div class="account-info">
|
||||
<h2>{username}</h2>
|
||||
<h3>UID: {uid}</h3>
|
||||
<h3 id="creationdate">{creationdate}</h3>
|
||||
<h3>Account Type: {type}</h3>
|
||||
<h3>Total Pastes: {totalpastes}</h3>
|
||||
<h3>Total Pastes Size: {totalsize}</h3>
|
||||
</div>
|
||||
<div class="collumn-2">
|
||||
<div class="pastes-wrapper">
|
||||
<h2 style="text-align: center;">Pastes</h2>
|
||||
<div class="pastes-container">
|
||||
{pastes}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
|
||||
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.account-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.account-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #222222;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
width: fit-content;
|
||||
width: 48%;
|
||||
max-width: 48%;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
word-break: keep-all;
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
.list-a {
|
||||
transition: background-color 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 90%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #2a2a2a;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: #3a3a3a00 2px solid;
|
||||
}
|
||||
|
||||
.list-a:hover {
|
||||
transition: background-color 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.collumn-2 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 48%;
|
||||
max-width: 48%;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
width: 85%;
|
||||
max-width: 100%;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
height: fit-content;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.pastes-container {
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user