bulletboards/ImageBoardServerApp/Pages/Accounts/UserPage.razor
limited_dev 9c93f9d10c !feat: removed the direct editing of passwords
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
2023-06-12 12:25:48 +02:00

63 lines
No EOL
2 KiB
Text

@page "/sys/you"
@using ImageBoardServerApp.Auth
@using ImageBoardServerApp.Data.Repository
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<PageTitle>YOU - Bulletboards</PageTitle>
<AuthorizeView>
<Authorized>
<h3>YOU</h3>
<br/>
<span>Email: @mail</span>
<br/>
<span>Email: </span>
<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>
<br/>
<a href="/sys/logout">[Logout]</a>
</Authorized>
<NotAuthorized>
<span>You are not logged in.</span>
<a class="navbar-brand" href="/sys/login">Please login first.</a>
</NotAuthorized>
</AuthorizeView>
@code {
private string mail { get; set; } = "";
private string newMail { 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;
}
}
private async Task changeEmail()
{
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)
{
return;
}
int userID = foundusr.UserID;
if (newMail == null || newMail == "" || !newMail.Contains("@"))
{
return;
}
foundusr.Email = newMail;
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
await UsersRepository.updateUserAsync(foundusr);
}
}