From 2724b6b9d233de6d0f45952b220adeaf03cbd5f7 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Tue, 7 Feb 2023 21:21:38 +0100 Subject: [PATCH 1/2] temp commit --- .../ImageBoardServerApp.csproj | 9 --- .../Pages/Accounts/Login.razor | 1 - .../Pages/Accounts/Register.razor | 67 +++++++++++++++++++ ImageBoardServerApp/Pages/Basic/Index.razor | 4 +- .../Pages/Moderation/ModMenu.razor | 31 +++++++++ .../Pages/Moderation/ReportsPage.razor | 5 ++ .../Shared/Components/Comment.razor | 4 ++ .../Shared/Components/Comment.razor.css | 9 ++- .../Shared/Components/Forms/CommentForm.razor | 4 +- .../Shared/Components/Forms/PostForm.razor | 4 +- .../Shared/Components/Post.razor | 5 +- .../Shared/Components/Post.razor.css | 6 +- .../Shared/Components/Reports.razor | 5 ++ ImageBoardServerApp/Shared/MainLayout.razor | 1 + 14 files changed, 136 insertions(+), 19 deletions(-) create mode 100644 ImageBoardServerApp/Pages/Accounts/Register.razor create mode 100644 ImageBoardServerApp/Pages/Moderation/ModMenu.razor create mode 100644 ImageBoardServerApp/Pages/Moderation/ReportsPage.razor create mode 100644 ImageBoardServerApp/Shared/Components/Reports.razor diff --git a/ImageBoardServerApp/ImageBoardServerApp.csproj b/ImageBoardServerApp/ImageBoardServerApp.csproj index 7866871..756ebf0 100644 --- a/ImageBoardServerApp/ImageBoardServerApp.csproj +++ b/ImageBoardServerApp/ImageBoardServerApp.csproj @@ -18,18 +18,9 @@ - - - - - - - - - diff --git a/ImageBoardServerApp/Pages/Accounts/Login.razor b/ImageBoardServerApp/Pages/Accounts/Login.razor index 3c53718..5483640 100644 --- a/ImageBoardServerApp/Pages/Accounts/Login.razor +++ b/ImageBoardServerApp/Pages/Accounts/Login.razor @@ -1,7 +1,6 @@ @page "/login" @using ImageBoardServerApp.Data.Repository @using ImageBoardServerApp.Auth -@using System.Runtime.InteropServices @inject IJSRuntime js @inject AuthenticationStateProvider authStateProvider @inject NavigationManager navManager diff --git a/ImageBoardServerApp/Pages/Accounts/Register.razor b/ImageBoardServerApp/Pages/Accounts/Register.razor new file mode 100644 index 0000000..b422d38 --- /dev/null +++ b/ImageBoardServerApp/Pages/Accounts/Register.razor @@ -0,0 +1,67 @@ +@page "/register" +@using ImageBoardServerApp.Data.Repository +@using ImageBoardServerApp.Auth +@inject IJSRuntime js +@inject AuthenticationStateProvider authStateProvider +@inject NavigationManager navManager + +

Register to bulletbroards

+
+
+
+ + +
+
+ + +
+ [Register] +
+ +
+@code { + private string Email { get; set; } + private string Password { get; set; } + + private bool verified; + + private async Task login() + { + Console.WriteLine("Registering..."); + UserData userToCreate = new UserData() + { + Email = Email, + Password = BCrypt.Net.BCrypt.HashPassword(Password), + Role = "User", + PermissionInteger = 1, + TimeBanned = -1 + }; + if (await UsersRepository.getUserByEmailAsync(Email) != null) + { + return; + } + await UsersRepository.createUserAsync(userToCreate); + Console.WriteLine("loggin you in..."); + var user = await UsersRepository.getUserByEmailAsync(Email); + if (user == null) + { + await js.InvokeVoidAsync("alert", "User does not exist"); + verified = false; + return; + } + verified = BCrypt.Net.BCrypt.Verify(Password, user.Password); + if (verified) + { + verified = true; + var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider; + await customAuthStateProvider.UpdateAuthenticationStateAsync(user); + navManager.NavigateTo("/", true); + return; + } + await js.InvokeVoidAsync("alert", $"Wrong Password"); + } +} +@code { + +} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Basic/Index.razor b/ImageBoardServerApp/Pages/Basic/Index.razor index 513b766..99a6427 100644 --- a/ImageBoardServerApp/Pages/Basic/Index.razor +++ b/ImageBoardServerApp/Pages/Basic/Index.razor @@ -6,8 +6,8 @@

BulletBoard

This is a simple Imageboard made in Razor.
-We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users. -
+We're currently hosting @amountOfPosts Threads, @amountOfComments Comments and @amountOfUsers Users. + @Details @code{ diff --git a/ImageBoardServerApp/Pages/Moderation/ModMenu.razor b/ImageBoardServerApp/Pages/Moderation/ModMenu.razor new file mode 100644 index 0000000..bdea895 --- /dev/null +++ b/ImageBoardServerApp/Pages/Moderation/ModMenu.razor @@ -0,0 +1,31 @@ +@page "/modmenu" +@using ImageBoardServerApp.Auth +@inject AuthenticationStateProvider authStateProvider +@inject NavigationManager navManager + + +

ModMenu

+ + + Welcome @mail to the mod menu +
+ [Reports] +
+
+ + You do not have permission to view this menu. + +
+@code { + private string mail { get; set; } = ""; + + protected override async Task OnInitializedAsync() + { + var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; + var user = await cauthStateProvder.GetAuthenticationStateAsync(); + if (user.User.Identity.IsAuthenticated) + { + mail = user.User.Identity.Name; + } + } +} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Moderation/ReportsPage.razor b/ImageBoardServerApp/Pages/Moderation/ReportsPage.razor new file mode 100644 index 0000000..aaebd07 --- /dev/null +++ b/ImageBoardServerApp/Pages/Moderation/ReportsPage.razor @@ -0,0 +1,5 @@ +@page "/modmenu/reports" + +@code { + +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor b/ImageBoardServerApp/Shared/Components/Comment.razor index 7b2ea75..192a56d 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor +++ b/ImageBoardServerApp/Shared/Components/Comment.razor @@ -9,6 +9,10 @@ @toggleText ] @comment.Username + @if (comment.User.Role != "User") + { + ##@comment.User.Role + } @getTimeFromUnix(comment.CreatedAt) No.@comment.CommentID diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor.css b/ImageBoardServerApp/Shared/Components/Comment.razor.css index b69acda..30f20bc 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor.css +++ b/ImageBoardServerApp/Shared/Components/Comment.razor.css @@ -58,4 +58,11 @@ .threadTextContainer{ margin: 0; -} \ No newline at end of file +} + +.Admin{ + color: #ff191c; +} +.Mod{ + color: #af13d7; +} diff --git a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor index 0a81474..883ab15 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor @@ -100,7 +100,7 @@ { Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 4); // max 2MB var file = Path.GetRandomFileName() + "." + selectedFile.Name.Split(".")[selectedFile.Name.Split(".").Length - 1]; - var path = $"{env.WebRootPath}\\img\\dynamic\\comment\\{@post.Board}\\{file}"; + var path = $"{env.WebRootPath}/img/dynamic/comment/{@post.Board}/{file}"; FileStream fs = File.Create(path); await stream.CopyToAsync(fs); stream.Close(); @@ -110,7 +110,7 @@ var imageToUpload = new ImageData { Board = post.Board, - ImageLocation = $"\\img\\dynamic\\comment\\{post.Board}\\{file}" + ImageLocation = $"/img/dynamic/comment/{post.Board}/{file}" }; int imageID = await ImagesRepository.createImageAsync(imageToUpload); commentToCreate = new CommentData() diff --git a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index 2389009..01338f2 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -120,7 +120,7 @@ Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 4); // max 2MB var file = Path.GetRandomFileName() + "." + selectedFile.Name.Split(".")[selectedFile.Name.Split(".").Length - 1]; - var path = $"{env.WebRootPath}\\img\\dynamic\\op\\{board.Tag}\\{file}"; + var path = $"{env.WebRootPath}/img/dynamic/op/{board.Tag}/{file}"; FileStream fs = File.Create(path); await stream.CopyToAsync(fs); stream.Close(); @@ -129,7 +129,7 @@ var imageToUpload = new ImageData { Board = board.Tag, - ImageLocation = $"\\img\\dynamic\\op\\{board.Tag}\\{file}" + ImageLocation = $"/img/dynamic/op/{board.Tag}/{file}" }; int imageID = await ImagesRepository.createImageAsync(imageToUpload); var postToPost = new PostData diff --git a/ImageBoardServerApp/Shared/Components/Post.razor b/ImageBoardServerApp/Shared/Components/Post.razor index af77439..b3d8f72 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor +++ b/ImageBoardServerApp/Shared/Components/Post.razor @@ -13,7 +13,10 @@ } @post.Title @post.Username - ##@post.User.Role + @if (post.User.Role != "User") + { + ##@post.User.Role. + } @getTimeFromUnix(post.CreatedAt) No.@post.PostID diff --git a/ImageBoardServerApp/Shared/Components/Post.razor.css b/ImageBoardServerApp/Shared/Components/Post.razor.css index 0233d02..2285ed7 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor.css +++ b/ImageBoardServerApp/Shared/Components/Post.razor.css @@ -16,9 +16,13 @@ color: #339305; } -.roleAdmin{ +.Admin{ color: #ff191c; } +.Mod{ + color: #af13d7; +} + .threadHeader{ text-align: left; diff --git a/ImageBoardServerApp/Shared/Components/Reports.razor b/ImageBoardServerApp/Shared/Components/Reports.razor new file mode 100644 index 0000000..0fe0732 --- /dev/null +++ b/ImageBoardServerApp/Shared/Components/Reports.razor @@ -0,0 +1,5 @@ +

Reports

+ +@code { + +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/MainLayout.razor b/ImageBoardServerApp/Shared/MainLayout.razor index b4d94cf..141e9c6 100644 --- a/ImageBoardServerApp/Shared/MainLayout.razor +++ b/ImageBoardServerApp/Shared/MainLayout.razor @@ -20,6 +20,7 @@ [Logout @mail] + [Register] [Login] From c1fd893ff02a47423ed0fbbc9ea18ee3b72d0e64 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Tue, 7 Feb 2023 21:47:28 +0100 Subject: [PATCH 2/2] fixed the bork --- ImageBoardServerApp/Data/CommentData.cs | 2 -- ImageBoardServerApp/Pages/Moderation/ModMenu.razor | 1 + ImageBoardServerApp/Pages/Moderation/UsersPage.razor | 6 ++++++ ImageBoardServerApp/Shared/Components/Comment.razor | 2 +- ImageBoardServerApp/Shared/Components/Comment.razor.css | 4 +++- .../Shared/Components/Forms/CommentForm.razor | 4 ++-- .../Shared/Components/Forms/PostForm.razor | 4 ++-- ImageBoardServerApp/Shared/Components/Post.razor | 8 ++++---- ImageBoardServerApp/Shared/Components/Post.razor.css | 2 +- ImageBoardServerApp/_Imports.razor | 2 -- 10 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 ImageBoardServerApp/Pages/Moderation/UsersPage.razor diff --git a/ImageBoardServerApp/Data/CommentData.cs b/ImageBoardServerApp/Data/CommentData.cs index bcaf8a1..14a5c5d 100644 --- a/ImageBoardServerApp/Data/CommentData.cs +++ b/ImageBoardServerApp/Data/CommentData.cs @@ -1,7 +1,5 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Diagnostics.CodeAnalysis; -using ImageBoardServerApp.Shared.Components; namespace ImageBoardServerApp.Data; diff --git a/ImageBoardServerApp/Pages/Moderation/ModMenu.razor b/ImageBoardServerApp/Pages/Moderation/ModMenu.razor index bdea895..ed7579a 100644 --- a/ImageBoardServerApp/Pages/Moderation/ModMenu.razor +++ b/ImageBoardServerApp/Pages/Moderation/ModMenu.razor @@ -10,6 +10,7 @@ Welcome @mail to the mod menu diff --git a/ImageBoardServerApp/Pages/Moderation/UsersPage.razor b/ImageBoardServerApp/Pages/Moderation/UsersPage.razor new file mode 100644 index 0000000..871b4c0 --- /dev/null +++ b/ImageBoardServerApp/Pages/Moderation/UsersPage.razor @@ -0,0 +1,6 @@ +@page "/modmenu/users" +

UsersPage

+ +@code { + +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor b/ImageBoardServerApp/Shared/Components/Comment.razor index 192a56d..1225ce6 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor +++ b/ImageBoardServerApp/Shared/Components/Comment.razor @@ -9,7 +9,7 @@ @toggleText ] @comment.Username - @if (comment.User.Role != "User") + @if (@comment.User.Role != "User") { ##@comment.User.Role } diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor.css b/ImageBoardServerApp/Shared/Components/Comment.razor.css index 30f20bc..4de11ba 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor.css +++ b/ImageBoardServerApp/Shared/Components/Comment.razor.css @@ -60,9 +60,11 @@ margin: 0; } + .Admin{ color: #ff191c; } + .Mod{ color: #af13d7; -} +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor index 883ab15..90bf2c6 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor @@ -100,7 +100,7 @@ { Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 4); // max 2MB var file = Path.GetRandomFileName() + "." + selectedFile.Name.Split(".")[selectedFile.Name.Split(".").Length - 1]; - var path = $"{env.WebRootPath}/img/dynamic/comment/{@post.Board}/{file}"; + var path = $"{env.WebRootPath}/img/dynamic/comment/{@post.Board}/{@file}"; FileStream fs = File.Create(path); await stream.CopyToAsync(fs); stream.Close(); @@ -110,7 +110,7 @@ var imageToUpload = new ImageData { Board = post.Board, - ImageLocation = $"/img/dynamic/comment/{post.Board}/{file}" + ImageLocation = $"/img/dynamic/comment/{@post.Board}/{@file}" }; int imageID = await ImagesRepository.createImageAsync(imageToUpload); commentToCreate = new CommentData() diff --git a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index 01338f2..cf54db9 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -120,7 +120,7 @@ Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 4); // max 2MB var file = Path.GetRandomFileName() + "." + selectedFile.Name.Split(".")[selectedFile.Name.Split(".").Length - 1]; - var path = $"{env.WebRootPath}/img/dynamic/op/{board.Tag}/{file}"; + var path = $"{env.WebRootPath}/img/dynamic/op/{@board.Tag}/{@file}"; FileStream fs = File.Create(path); await stream.CopyToAsync(fs); stream.Close(); @@ -129,7 +129,7 @@ var imageToUpload = new ImageData { Board = board.Tag, - ImageLocation = $"/img/dynamic/op/{board.Tag}/{file}" + ImageLocation = $"/img/dynamic/op/{@board.Tag}/{@file}" }; int imageID = await ImagesRepository.createImageAsync(imageToUpload); var postToPost = new PostData diff --git a/ImageBoardServerApp/Shared/Components/Post.razor b/ImageBoardServerApp/Shared/Components/Post.razor index b3d8f72..2e493a2 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor +++ b/ImageBoardServerApp/Shared/Components/Post.razor @@ -14,9 +14,9 @@ @post.Title @post.Username @if (post.User.Role != "User") - { - ##@post.User.Role. - } + { + ##@post.User.Role + } @getTimeFromUnix(post.CreatedAt) No.@post.PostID @@ -36,7 +36,7 @@
@foreach (string s in @post.Content.Split("\n")) { - @if (s.StartsWith(">")) + @if (@s.StartsWith(">")) { @s } diff --git a/ImageBoardServerApp/Shared/Components/Post.razor.css b/ImageBoardServerApp/Shared/Components/Post.razor.css index 2285ed7..2cee082 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor.css +++ b/ImageBoardServerApp/Shared/Components/Post.razor.css @@ -19,11 +19,11 @@ .Admin{ color: #ff191c; } + .Mod{ color: #af13d7; } - .threadHeader{ text-align: left; } diff --git a/ImageBoardServerApp/_Imports.razor b/ImageBoardServerApp/_Imports.razor index 3e6f6b8..3613cc4 100644 --- a/ImageBoardServerApp/_Imports.razor +++ b/ImageBoardServerApp/_Imports.razor @@ -6,8 +6,6 @@ @using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.JSInterop -@using ImageBoardServerApp -@using ImageBoardServerApp.Shared @using Radzen @using Radzen.Blazor @using ImageBoardServerApp