feat: The posts are now sorted
fix: modmenu now checks for the permission, you now have to be 18yo to access the boards, images now get deleted when deleting threads / posts, fixed grammar error in the register page, other fixed which i forget
This commit is contained in:
parent
f0fbb11824
commit
dcc7634f5e
13 changed files with 219 additions and 88 deletions
|
@ -27,6 +27,9 @@ public static class UsersRepository
|
|||
return await db.Users
|
||||
.Where(user => user.Email == email)
|
||||
.Include(user => user.SubmittedReports)
|
||||
.Include(user => user.Posts)
|
||||
.Include(user => user.Comments)
|
||||
.Include(user => user.RecivedReports)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
|
83
ImageBoardServerApp/Data/TheManager.cs
Normal file
83
ImageBoardServerApp/Data/TheManager.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using ImageBoardServerApp.Data.Repository;
|
||||
|
||||
namespace ImageBoardServerApp.Data;
|
||||
|
||||
public class TheManager
|
||||
{
|
||||
|
||||
private static long getDiff(PostData post)
|
||||
{
|
||||
return (DateTimeOffset.Now.ToUnixTimeMilliseconds() - post.CreatedAt);
|
||||
}
|
||||
|
||||
private static long getValue(long num)
|
||||
{
|
||||
return num < 0 ? num * -1 : num;
|
||||
}
|
||||
|
||||
public static long getBumpValue(PostData post)
|
||||
{
|
||||
return getValue( 10 * 60000 - getDiff(post)) + getDiff(post) / post.Comments.Count;
|
||||
}
|
||||
|
||||
public static async Task<List<PostData>> getPostList(string boardTag)
|
||||
{
|
||||
List<PostData> threads = await PostsRepository.getPostsByBoardAsync(boardTag);
|
||||
return threads.OrderBy(getBumpValue).ToList();
|
||||
}
|
||||
|
||||
public static async Task bumpThreads(BoardData board)
|
||||
{
|
||||
List<PostData> sortedThreads = await getPostList(board.Tag);
|
||||
if (sortedThreads.Count > board.maxThreads + 1)
|
||||
{
|
||||
for (int i = board.maxThreads + 1; i >= sortedThreads.Count; ++i)
|
||||
{
|
||||
await deleteThread(sortedThreads[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task deleteThread(PostData post)
|
||||
{
|
||||
foreach(var c in post.Comments)
|
||||
{
|
||||
if (c.Image != null)
|
||||
{
|
||||
deleteImage(c.Image);
|
||||
}
|
||||
}
|
||||
|
||||
deleteImage(post.Image);
|
||||
|
||||
await PostsRepository.deletePostAsync(post.PostID);
|
||||
}
|
||||
|
||||
public static async Task deleteComment(CommentData comment)
|
||||
{
|
||||
if (comment.Image != null)
|
||||
{
|
||||
deleteImage(comment.Image);
|
||||
}
|
||||
|
||||
await CommentsRepository.deleteCommentAsync(comment.CommentID);
|
||||
}
|
||||
|
||||
public static void deleteImage(ImageData imageData)
|
||||
{
|
||||
string path = $"./wwwroot{imageData.ImageLocation}";
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
Console.WriteLine("The file was not found.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("An error occurred: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,8 +18,8 @@
|
|||
</div>
|
||||
<a @onclick="login" href="javascript:void(0)">[Register]</a>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<span>By registering you confirm that you are atleast 18 years of age.</span>
|
||||
@code {
|
||||
private string Email { get; set; }
|
||||
private string Password { get; set; }
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<a class="navbar-brand" href="/sys/login">Please login first.</a>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
|
||||
private string mail { get; set; } = "";
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
@inject AuthenticationStateProvider authStateProvider
|
||||
@inject NavigationManager navManager
|
||||
|
||||
<AuthorizeView>
|
||||
<AuthorizeView Roles="Admin,Mod">
|
||||
<Authorized>
|
||||
<h3>ModMenu</h3>
|
||||
<span>Welcome @mail to the mod menu</span>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
@page "/sys/reports"
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
<AuthorizeView>
|
||||
<AuthorizeView Roles="Admin,Mod">
|
||||
<Authorized>
|
||||
<h3>Reports</h3>
|
||||
@foreach (var r in reports)
|
||||
{
|
||||
<Report report="r"/>
|
||||
<ReportEntry report="r"/>
|
||||
<hr/>
|
||||
}
|
||||
</Authorized>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@page "/sys/users"
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
<AuthorizeView>
|
||||
<AuthorizeView Roles="Admin">
|
||||
<Authorized>
|
||||
<h3>Users</h3>
|
||||
@foreach (var u in users)
|
||||
|
|
|
@ -4,20 +4,22 @@
|
|||
|
||||
<PageTitle>/@board.Tag/ - @board.Topic - BulletBoard</PageTitle>
|
||||
|
||||
<div class="boardHeader">
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="boardHeader">
|
||||
<h3>@board.Topic Board</h3>
|
||||
<PostForm board="@board"/>
|
||||
<PageFooter/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<h3>Threads</h3>
|
||||
<br/>
|
||||
@if (posts != null)
|
||||
{
|
||||
<h3>Threads</h3>
|
||||
<br/>
|
||||
@if (posts != null)
|
||||
{
|
||||
@if (posts.Any())
|
||||
{
|
||||
@foreach(var post in posts)
|
||||
|
@ -26,13 +28,21 @@
|
|||
<hr/>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>
|
||||
<em>Loading Posts...</em>
|
||||
</p>
|
||||
}
|
||||
}
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<div class="notLoggedIn">
|
||||
<span>You are not logged in.</span>
|
||||
<a class="navbar-brand" href="/sys/login">Please login first.</a>
|
||||
</div>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
|
||||
|
@ -40,7 +50,7 @@ else
|
|||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
posts = await PostsRepository.getPostsByBoardAsync(board.Tag);
|
||||
posts = await TheManager.getPostList(board.Tag);
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
.boardHeader{
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
|
||||
.notLoggedIn{
|
||||
text-align: center;
|
||||
}
|
|
@ -9,9 +9,9 @@
|
|||
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
|
||||
<span>]</span>
|
||||
<span class="name">@comment.Username</span>
|
||||
@if (@comment.User.Role != "User")
|
||||
@if (@role != "User")
|
||||
{
|
||||
<span class="@comment.User.Role" >##@comment.User.Role</span>
|
||||
<span class="@role" >##@role</span>
|
||||
}
|
||||
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
|
||||
<span class="post-id">No.@comment.CommentID</span>
|
||||
|
@ -61,7 +61,7 @@
|
|||
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
||||
if (foundusr.PermissionInteger >= 50 || comment.UserID == foundusr.UserID)
|
||||
{
|
||||
await CommentsRepository.deleteCommentAsync(comment.CommentID);
|
||||
await TheManager.deleteComment(comment);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@
|
|||
}
|
||||
|
||||
private ImageData image;
|
||||
private string role;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
@ -90,6 +91,9 @@
|
|||
{
|
||||
image = await ImagesRepository.getImageByIdAsync(i);
|
||||
}
|
||||
|
||||
var cmt = await CommentsRepository.getCommentByIdAsync(comment.CommentID);
|
||||
role = cmt.User.Role;
|
||||
}
|
||||
|
||||
private bool opened = true;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@using ImageBoardServerApp.Data
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
@inject AuthenticationStateProvider authStateProvider
|
||||
@inject NavigationManager navigationManager;
|
||||
|
||||
<div class="threadHeader">
|
||||
@if (showOpenThread)
|
||||
|
@ -12,12 +13,13 @@
|
|||
<span>]</span>
|
||||
}
|
||||
<span class="title">@post.Title</span>
|
||||
<span class="name">@post.Username</span>
|
||||
<span class="name">@post.Username </span>
|
||||
@if (post.User.Role != "User")
|
||||
{
|
||||
<span class="@post.User.Role" >##@post.User.Role</span>
|
||||
<span class="@post.User.Role">##@post.User.Role </span>
|
||||
}
|
||||
<span class="date">@getTimeFromUnix(post.CreatedAt)</span>
|
||||
<span> </span>
|
||||
<span class="date"> @getTimeFromUnix(post.CreatedAt)</span>
|
||||
<span class="post-id">No.@post.PostID</span>
|
||||
</div>
|
||||
@if (opened)
|
||||
|
@ -81,13 +83,15 @@
|
|||
|
||||
private async Task deletePost()
|
||||
{
|
||||
string boardTag = post.Board;
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
||||
if (foundusr.PermissionInteger >= 50 || post.UserID == foundusr.UserID)
|
||||
{
|
||||
await PostsRepository.deletePostAsync(post.PostID);
|
||||
await TheManager.deleteThread(post);
|
||||
navigationManager.NavigateTo($"/{boardTag}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
@using System.ComponentModel.DataAnnotations
|
||||
<div>
|
||||
@if (report.Type == "op")
|
||||
{
|
||||
<span> /@report.ReportedPost.Board/ </span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span> /@report.ReportedComment.Board/ </span>
|
||||
}
|
||||
<span>#@report.ReportID</span>
|
||||
<span>@report.Type</span>
|
||||
<br/>
|
||||
<span>Reason: @report.ReportReason</span>
|
||||
<br/>
|
||||
<span>Explaination: @report.ReportExlaination</span>
|
||||
<br/>
|
||||
<a @onclick="@banTarget" href="javascript:void(0)">Ban Reported User</a>
|
||||
<br/>
|
||||
<a @onclick="@banReporter" href="javascript:void(0)" >Ban Reporter</a>
|
||||
<br/>
|
||||
@if (report.Type == "op")
|
||||
{
|
||||
<Post post="report.ReportedPost" showOpenThread="true"></Post>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Comment comment="report.ReportedComment"></Comment>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
[Required]
|
||||
public ReportData report { get; set; }
|
||||
|
||||
|
||||
private async Task banTarget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async Task banReporter()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
70
ImageBoardServerApp/Shared/Components/ReportEntry.razor
Normal file
70
ImageBoardServerApp/Shared/Components/ReportEntry.razor
Normal file
|
@ -0,0 +1,70 @@
|
|||
@using System.ComponentModel.DataAnnotations
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
<div>
|
||||
@if (report.Type == "op")
|
||||
{
|
||||
<span> /@report.ReportedPost.Board/ </span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span> /@report.ReportedComment.Board/ </span>
|
||||
}
|
||||
<span>#@report.ReportID</span>
|
||||
<span>@report.Type</span>
|
||||
<br/>
|
||||
<span>Reason: @report.ReportReason</span>
|
||||
<br/>
|
||||
<span>Explaination: @report.ReportExlaination</span>
|
||||
<br/>
|
||||
<span>Ban User: </span>
|
||||
<a @onclick="() => banTarget(1)" href="javascript:void(0)">1 Tag</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banTarget(7)" href="javascript:void(0)">7 Tage</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banTarget(31)" href="javascript:void(0)">31 Tage</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banTarget(365)" href="javascript:void(0)">365 Tage</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banTarget(99999999)" href="javascript:void(0)">99M Tage</a>
|
||||
<br/>
|
||||
<span>Ban Reporter: </span>
|
||||
<a @onclick="() => banReporter(1)" href="javascript:void(0)">1 Tag</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banReporter(7)" href="javascript:void(0)">7 Tage</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banReporter(31)" href="javascript:void(0)">31 Tage</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banReporter(365)" href="javascript:void(0)">365 Tage</a>
|
||||
<span> </span>
|
||||
<a @onclick="() => banReporter(99999999)" href="javascript:void(0)">99M Tage</a>
|
||||
<br/>
|
||||
@if (report.Type == "op")
|
||||
{
|
||||
<Post post="report.ReportedPost" showOpenThread="true"></Post>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Comment comment="report.ReportedComment"></Comment>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
[Required]
|
||||
public ReportData report { get; set; }
|
||||
|
||||
|
||||
private async Task banTarget(int days)
|
||||
{
|
||||
UserData user = report.UserReported;
|
||||
user.TimeBanned = DateTimeOffset.Now.AddDays(days).ToUnixTimeMilliseconds();
|
||||
await UsersRepository.updateUserAsync(user);
|
||||
}
|
||||
|
||||
private async Task banReporter(int days)
|
||||
{
|
||||
UserData user = report.UserReporter;
|
||||
user.TimeBanned = DateTimeOffset.Now.AddDays(days).ToUnixTimeMilliseconds();
|
||||
await UsersRepository.updateUserAsync(user);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue