diff --git a/ImageBoardServerApp/Data/UserData.cs b/ImageBoardServerApp/Data/UserData.cs index 438c4d2..ebe568b 100644 --- a/ImageBoardServerApp/Data/UserData.cs +++ b/ImageBoardServerApp/Data/UserData.cs @@ -1,6 +1,5 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Net; namespace ImageBoardServerApp.Data; @@ -34,4 +33,6 @@ public class UserData public List SubmittedReports { get; set; } public List RecivedReports { get; set; } + + public string LastUsedName { get; set; } } \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Accounts/Register.razor b/ImageBoardServerApp/Pages/Accounts/Register.razor index f16a907..c955f09 100644 --- a/ImageBoardServerApp/Pages/Accounts/Register.razor +++ b/ImageBoardServerApp/Pages/Accounts/Register.razor @@ -43,7 +43,8 @@ Email = Email, Password = BCrypt.Net.BCrypt.HashPassword(Password), Role = "User", - TimeBanned = -1 + TimeBanned = -1, + LastUsedName = "Anonymous" }; if (await UsersRepository.getUserByEmailAsync(Email) != null) { diff --git a/ImageBoardServerApp/Pages/FetchData.razor b/ImageBoardServerApp/Pages/FetchData.razor deleted file mode 100644 index 3ba8adc..0000000 --- a/ImageBoardServerApp/Pages/FetchData.razor +++ /dev/null @@ -1,60 +0,0 @@ -@page "/fetchdata" -@inject HttpClient Http - -Weather forecast - -

Weather forecast

- -

This component demonstrates fetching data from the server.

- -@if (forecasts == null) -{ -

- Loading... -

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - forecasts = await Http.GetFromJsonAsync("sample-data/weather.json"); - } - - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public string? Summary { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } - -} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Board.razor b/ImageBoardServerApp/Shared/Components/Board.razor index c489980..d9b4668 100644 --- a/ImageBoardServerApp/Shared/Components/Board.razor +++ b/ImageBoardServerApp/Shared/Components/Board.razor @@ -1,5 +1,7 @@ @using ImageBoardServerApp.Util @using System.ComponentModel.DataAnnotations +@inject NavigationManager navigationManager; + /@board.Tag/ - @board.Topic - BulletBoard @@ -49,7 +51,14 @@ protected override async Task OnParametersSetAsync() { - posts = await TheManager.getPostList(board.Tag); + try + { + posts = await TheManager.getPostList(board.Tag); + } + catch + { + navigationManager.NavigateTo("/sys/dead"); + } } [Parameter] diff --git a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor index 7b0b7a6..8b58538 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor @@ -1,7 +1,6 @@ @using System.ComponentModel.DataAnnotations @using ImageBoardServerApp.Auth @using ImageBoardServerApp.Data.Repository - @inject NavigationManager navigationManager @inject IWebHostEnvironment env @inject AuthenticationStateProvider authStateProvider @@ -56,9 +55,25 @@ [Required] public PostData post { get; set; } - string postUsername { get; set; } = "Anonymous"; + string postUsername { get; set; } string postContent { get; set; } = ""; + protected override async Task OnParametersSetAsync() + { + var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; + var user = await cauthStateProvder.GetAuthenticationStateAsync(); + var usr = user.User; + UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name); + if (foundusr == null) + { + hasErr = true; + postErr = "You are not logged in."; + return; + } + postUsername = foundusr.LastUsedName; + await base.OnParametersSetAsync(); + } + private IBrowserFile selectedFile; private async Task SingleUpload(InputFileChangeEventArgs e) @@ -96,6 +111,11 @@ return; } foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + if (postUsername == null || postUsername == "") + { + postUsername = "Anonymous"; + } + foundusr.LastUsedName = postUsername; await UsersRepository.updateUserAsync(foundusr); PostData updatedPost = await PostsRepository.getPostByIdAsync(post.PostID); @@ -115,10 +135,6 @@ } bool hasImage = selectedFile != null; - if (postUsername == null || postUsername == "") - { - postUsername = "Anonymous"; - } int thisGET = b.NumberOfGETs + 1; b.NumberOfGETs++; await BoardsRepository.updateBoardAsync(b); @@ -133,7 +149,6 @@ stream.Close(); fs.Close(); - var imageToUpload = new ImageData { Board = post.Board, diff --git a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index b126e06..5241ea4 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -60,10 +60,26 @@ [Required] public BoardData board { get; set; } = new BoardData(); - string postUsername { get; set; } = "Anonymous"; + string postUsername { get; set; } string postTitle { get; set; } = ""; string postContent { get; set; } = ""; + protected override async Task OnParametersSetAsync() + { + var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; + var user = await cauthStateProvder.GetAuthenticationStateAsync(); + var usr = user.User; + UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name); + if (foundusr == null) + { + hasErr = true; + postErr = "You are not logged in."; + return; + } + postUsername = foundusr.LastUsedName; + await base.OnParametersSetAsync(); + } + private IBrowserFile selectedFile; @@ -79,7 +95,6 @@ private async Task onPostClick() { - var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; var user = await cauthStateProvder.GetAuthenticationStateAsync(); var usr = user.User; @@ -113,6 +128,11 @@ } foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + if (postUsername == null || postUsername == "") + { + postUsername = "Anonymous"; + } + foundusr.LastUsedName = postUsername; await UsersRepository.updateUserAsync(foundusr); @@ -139,10 +159,6 @@ ImageLocation = $"/img/dynamic/op/{@board.Tag}/{@file}" }; int imageID = await ImagesRepository.createImageAsync(imageToUpload); - if (postUsername == null || postUsername == "") - { - postUsername = "Anonymous"; - } int thisGET = b.NumberOfGETs + 1; b.NumberOfGETs++; diff --git a/ImageBoardServerApp/Shared/MainLayout.razor.css b/ImageBoardServerApp/Shared/MainLayout.razor.css index 56760ef..fd681aa 100644 --- a/ImageBoardServerApp/Shared/MainLayout.razor.css +++ b/ImageBoardServerApp/Shared/MainLayout.razor.css @@ -2,11 +2,12 @@ position: relative; display: flex; flex-direction: column; + background-color: #181223; } main { flex: 1; - background-color: #282a36; + background-color: #181223; color: #f8f8f2; padding: 0; margin: 0; diff --git a/ImageBoardServerApp/wwwroot/css/site.css b/ImageBoardServerApp/wwwroot/css/site.css index 96b0583..b749bd6 100644 --- a/ImageBoardServerApp/wwwroot/css/site.css +++ b/ImageBoardServerApp/wwwroot/css/site.css @@ -24,6 +24,7 @@ a, .btn-link { .content { padding-top: 1.1rem; + background-color: #181223; } .valid.modified:not([type=checkbox]) {