fix: fixed auth issues
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
766e6054dc
commit
6630b4963e
11 changed files with 308 additions and 243 deletions
|
@ -30,11 +30,12 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
|||
new Claim(ClaimTypes.Name, userSession.UserID.ToString()),
|
||||
new Claim(ClaimTypes.Role, userSession.Role)
|
||||
}, "CustomAuth"));
|
||||
return await Task.FromResult(new AuthenticationState(claimsPrincipal));
|
||||
return new AuthenticationState(claimsPrincipal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return await Task.FromResult(new AuthenticationState(_anonymous));
|
||||
Console.WriteLine("Returned Anon Auth due to err");
|
||||
return new AuthenticationState(_anonymous);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
{
|
||||
return;
|
||||
}
|
||||
int userID = foundusr.UserID;
|
||||
if (newMail == null || newMail == "" || !newMail.Contains("@"))
|
||||
{
|
||||
return;
|
||||
|
@ -60,4 +59,5 @@
|
|||
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
await UsersRepository.updateUserAsync(foundusr);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
@page "/"
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
@using ImageBoardServerApp.Auth
|
||||
@inject AuthenticationStateProvider authStateProvider
|
||||
|
||||
<h1>BulletBoard</h1>
|
||||
|
@ -22,25 +21,16 @@
|
|||
private int amountOfPosts = -1;
|
||||
private int amountOfComments = -1;
|
||||
private int amountOfUsers = -1;
|
||||
protected override async Task OnInitializedAsync()
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
if (user.User.Identity.IsAuthenticated)
|
||||
{
|
||||
var usr = user.User.Identity.Name;
|
||||
Details = $"Welcome {usr}";
|
||||
}
|
||||
else
|
||||
{
|
||||
Details = "Please log in first.";
|
||||
}
|
||||
var posts = await PostsRepository.getPostsAsync();
|
||||
amountOfPosts = posts.Count;
|
||||
var comments = await CommentsRepository.getCommentsAsync();
|
||||
amountOfComments = comments.Count;
|
||||
var users = await UsersRepository.getUsersAsync();
|
||||
amountOfUsers = users.Count;
|
||||
await base.OnParametersSetAsync();
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
<AuthorizeView Roles="Admin,Mod">
|
||||
<Authorized>
|
||||
<h3>ModMenu</h3>
|
||||
<span>Welcome @mail to the mod menu</span>
|
||||
<span>Welcome User #@mail to the mod menu</span>
|
||||
<div>
|
||||
<a href="/sys/modmenu/reports">[Reports]</a>
|
||||
<a href="/sys/modmenu/users">[Users]</a>
|
||||
|
@ -17,6 +17,7 @@
|
|||
<DeadLink/>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
private string mail { get; set; } = "";
|
||||
|
||||
|
@ -29,4 +30,10 @@
|
|||
mail = user.User.Identity.Name;
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
}
|
|
@ -50,8 +50,7 @@
|
|||
className2 = "redText";
|
||||
<span
|
||||
@onmouseenter="() => onHover(x1, y1, commentNumber)"
|
||||
@onmouseleave="() => onHover(x1, y1, -1)" class="threadMsg @className2"
|
||||
>
|
||||
@onmouseleave="() => onHover(x1, y1, -1)" class="threadMsg @className2">
|
||||
@line
|
||||
</span>
|
||||
@if (hoveringOver.p != -1 && hoveringOver == (x, y, commentNumber) && (hoverComment.ContainsKey(commentNumber) || hoverPost.ContainsKey(commentNumber)))
|
||||
|
@ -77,7 +76,6 @@
|
|||
</span>
|
||||
}
|
||||
<span> </span>
|
||||
|
||||
}
|
||||
</span>
|
||||
}
|
||||
|
@ -96,7 +94,6 @@
|
|||
</div>
|
||||
|
||||
|
||||
|
||||
@code {
|
||||
private string reportURL { get; set; }
|
||||
|
||||
|
@ -117,7 +114,7 @@
|
|||
hoveringOver = (x, y, p);
|
||||
}
|
||||
|
||||
public bool canDel { get; set; }
|
||||
public bool canDel { get; set; } = false;
|
||||
|
||||
private async Task deletePost()
|
||||
{
|
||||
|
@ -145,18 +142,6 @@
|
|||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await base.OnParametersSetAsync();
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
if (foundusr != null && (foundusr.Role != "User" || comment.UserID == foundusr.UserID))
|
||||
{
|
||||
canDel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canDel = false;
|
||||
}
|
||||
|
||||
|
||||
hoverComment = new Dictionary<int, CommentData>();
|
||||
|
@ -196,6 +181,23 @@
|
|||
reportURL = $"/sys/report/comment/{comment.Board}/{comment.CommentID}";
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
if (foundusr != null && (foundusr.Role != "User" || comment.UserID == foundusr.UserID))
|
||||
{
|
||||
canDel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canDel = false;
|
||||
}
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
int i;
|
||||
|
@ -228,6 +230,7 @@
|
|||
|
||||
private string toggleText2 = "-";
|
||||
private bool showHover = false;
|
||||
|
||||
private void ToggleHovered(MouseEventArgs e, string id)
|
||||
{
|
||||
showHover = !showHover;
|
||||
|
@ -237,4 +240,5 @@
|
|||
[Parameter]
|
||||
[Required]
|
||||
public CommentData comment { get; set; }
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
@using System.Text.RegularExpressions
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Text.RegularExpressions
|
||||
<div class="comment">
|
||||
|
||||
<span class="name">@comment.Username</span>
|
||||
@if (@role != "User")
|
||||
{
|
||||
|
@ -13,12 +15,12 @@ else
|
|||
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
|
||||
<span class="post-id">No.@comment.GET</span>
|
||||
<div class="threadContent">
|
||||
<div class="threadImage">
|
||||
@if (image != null)
|
||||
{
|
||||
<div class="threadImage">
|
||||
<img src="@($"{image.ImageLocation}?size=258x258")" alt="No Image found"/>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div class="threadTextContainer">
|
||||
@foreach (string s in @comment.Content.Split("\n"))
|
||||
{
|
||||
|
@ -46,12 +48,13 @@ else
|
|||
</span>
|
||||
}
|
||||
<span> </span>
|
||||
|
||||
}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private ImageData image;
|
||||
private string role;
|
||||
|
@ -87,4 +90,5 @@ else
|
|||
[Parameter]
|
||||
[Required]
|
||||
public CommentData comment { get; set; }
|
||||
|
||||
}
|
|
@ -27,6 +27,9 @@
|
|||
|
||||
.threadHeader{
|
||||
text-align: left;
|
||||
background-color: #241938;
|
||||
border-bottom: 2px solid #2d2a42;
|
||||
margin-inside: 2px;
|
||||
}
|
||||
|
||||
.threadFooter{
|
||||
|
@ -48,6 +51,8 @@
|
|||
max-width: 500px;
|
||||
max-height: 500px;
|
||||
padding: 5px;
|
||||
border: 1px solid #2d2a42;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.threadImage img{
|
||||
|
@ -56,7 +61,6 @@
|
|||
}
|
||||
|
||||
.threadImage img.active{
|
||||
/*transform: scale(3);*/
|
||||
max-width:500px;
|
||||
width: 100%;
|
||||
}
|
||||
|
@ -77,3 +81,58 @@
|
|||
.Mod {
|
||||
color: #bd93f9;
|
||||
}
|
||||
|
||||
.comment {
|
||||
border: 2px solid #2d2a42;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.threadFooter button {
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 4px 8px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
margin: 4px 2px;
|
||||
transition-duration: 0.4s;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.threadFooter a {
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 4px 8px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
margin: 4px 2px;
|
||||
transition-duration: 0.4s;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.delButton {
|
||||
background-color: #433F6B;
|
||||
color: white;
|
||||
border: 2px solid #ff5555;
|
||||
}
|
||||
|
||||
.delButton:hover {
|
||||
background-color: #ff5555;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.repButton {
|
||||
background-color: #433F6B;
|
||||
color: white;
|
||||
border: 2px solid #ffa255;
|
||||
}
|
||||
|
||||
.repButton:hover {
|
||||
background-color: #ffa255;
|
||||
color: white;
|
||||
}
|
|
@ -58,7 +58,7 @@
|
|||
string postUsername { get; set; }
|
||||
string postContent { get; set; } = "";
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
|
@ -71,7 +71,7 @@
|
|||
return;
|
||||
}
|
||||
postUsername = foundusr.LastUsedName;
|
||||
await base.OnParametersSetAsync();
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
private IBrowserFile selectedFile;
|
||||
|
@ -196,4 +196,5 @@
|
|||
navigationManager.NavigateTo($"/{post.Board}/thread/{post.PostID}", true, true);
|
||||
opened = false;
|
||||
}
|
||||
|
||||
}
|
|
@ -64,7 +64,7 @@
|
|||
string postTitle { get; set; } = "";
|
||||
string postContent { get; set; } = "";
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
|
@ -77,10 +77,9 @@
|
|||
return;
|
||||
}
|
||||
postUsername = foundusr.LastUsedName;
|
||||
await base.OnParametersSetAsync();
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
|
||||
private IBrowserFile selectedFile;
|
||||
|
||||
|
||||
|
@ -194,4 +193,5 @@
|
|||
Console.WriteLine("Shit sucks and did not work.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -127,7 +127,7 @@
|
|||
private string threadURL { get; set; }
|
||||
private string openThreadName { get; set; }
|
||||
|
||||
public bool canDel { get; set; }
|
||||
public bool canDel { get; set; } = false;
|
||||
public bool isActive { get; set; } = false;
|
||||
|
||||
private int linecnt = 0;
|
||||
|
@ -178,28 +178,38 @@
|
|||
toggleText = opened ? "-" : "+";
|
||||
}
|
||||
|
||||
private int usrid { get; set; }
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnParametersSetAsync();
|
||||
value = TheManager.getBumpValue(post) + "v";
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
|
||||
reportURL = $"/sys/report/op/{post.Board}/{post.PostID}";
|
||||
threadURL = $"/{post.Board}/thread/{post.PostID}";
|
||||
openThreadName = $"({post.Comments.Count}) View Thread";
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
if (usrid == null)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
usrid = int.Parse(user.User.Identity.Name);
|
||||
}
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(usrid);
|
||||
if (foundusr != null && (foundusr.Role != "User" || post.UserID == foundusr.UserID))
|
||||
{
|
||||
canDel = true;
|
||||
return;
|
||||
}
|
||||
canDel = false;
|
||||
await base.SetParametersAsync(parameters);
|
||||
}
|
||||
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public PostData post { get; set; }
|
||||
|
@ -208,4 +218,5 @@
|
|||
[Parameter]
|
||||
[Required]
|
||||
public bool showOpenThread { get; set; }
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
@using ImageBoardServerApp.Auth
|
||||
@inherits LayoutComponentBase
|
||||
@inherits LayoutComponentBase
|
||||
@inject AuthenticationStateProvider authStateProvider
|
||||
@inject NavigationManager navManager
|
||||
|
||||
|
@ -20,15 +19,4 @@
|
|||
@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 = $"Welcome User # {user.User.Identity.Name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue