fix: fixed auth issues

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-12 18:51:25 +02:00
parent 766e6054dc
commit 6630b4963e
11 changed files with 308 additions and 243 deletions

View file

@ -13,7 +13,7 @@
<span>Email: @mail</span>
<br/>
<span>Email: </span>
<input type="email" id="email" @bind="newMail" />
<input type="email" id="email" @bind="newMail"/>
<a @onclick="changeEmail" href="javascript:void(0)">[Change Email]</a>
<br/>
<a href="/sys/resetpw">[Change Password]</a>
@ -27,7 +27,7 @@
</AuthorizeView>
@code {
private string mail { get; set; } = "";
private string newMail { get; set; }
@ -40,7 +40,7 @@
mail = user.User.Identity.Name;
}
}
private async Task changeEmail()
{
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
@ -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);
}
}

View file

@ -1,6 +1,5 @@
@page "/"
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@inject AuthenticationStateProvider authStateProvider
<h1>BulletBoard</h1>
@ -18,29 +17,20 @@
@code{
private string Details { get; set; }
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();
}
}

View file

@ -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);
}
}