diff --git a/ImageBoardServerApp/Pages/_Host.cshtml b/ImageBoardServerApp/Pages/_Host.cshtml index 630ed2f..4b19541 100644 --- a/ImageBoardServerApp/Pages/_Host.cshtml +++ b/ImageBoardServerApp/Pages/_Host.cshtml @@ -3,7 +3,6 @@ @namespace ImageBoardServerApp.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers - @@ -16,6 +15,7 @@ + diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor b/ImageBoardServerApp/Shared/Components/Comment.razor index dbe28c1..5ca4456 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor +++ b/ImageBoardServerApp/Shared/Components/Comment.razor @@ -73,6 +73,8 @@ @code { + public bool canDel { get; set; } + private async Task deletePost() { var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; @@ -95,7 +97,21 @@ private ImageData image; private string role; - + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; + var user = await cauthStateProvder.GetAuthenticationStateAsync(); + var usr = user.User; + UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name); + if (foundusr != null && (foundusr.Role != "User" || comment.UserID == foundusr.UserID)) + { + canDel = true; + } + canDel = false; + } + protected override async Task OnInitializedAsync() { int i; diff --git a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index 4e2fa9d..a3da72c 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -28,7 +28,7 @@
- +
diff --git a/ImageBoardServerApp/Shared/Components/Post.razor b/ImageBoardServerApp/Shared/Components/Post.razor index 5aa82ea..bebc901 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor +++ b/ImageBoardServerApp/Shared/Components/Post.razor @@ -93,10 +93,12 @@ ] - - [ - Delete - ] + @if (canDel) + { + [ + Delete + ] + } [ Report ] @@ -118,6 +120,8 @@ @code { + + public bool canDel { get; set; } private async void lockMe() { @@ -137,7 +141,7 @@ dateTime = dateTime.AddMilliseconds( javaTimeStamp ).ToLocalTime(); return dateTime; } - + private async Task deletePost() { string boardTag = post.Board; @@ -165,9 +169,21 @@ toggleText = opened ? "-" : "+"; } - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { + await base.OnAfterRenderAsync(firstRender); value = TheManager.getBumpValue(post) + "v"; + 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 != null && (foundusr.Role != "User" || post.UserID == foundusr.UserID)) + { + canDel = true; + return; + } + canDel = false; } [Parameter] diff --git a/ImageBoardServerApp/Shared/NavMenu.razor b/ImageBoardServerApp/Shared/NavMenu.razor index 81cabe2..cd5b10b 100644 --- a/ImageBoardServerApp/Shared/NavMenu.razor +++ b/ImageBoardServerApp/Shared/NavMenu.razor @@ -5,7 +5,7 @@