bulletboards/ImageBoardServerApp/Pages/Accounts/UserPage.razor

63 lines
2 KiB
Text
Raw Normal View History

@page "/sys/you"
2023-02-12 18:06:33 +00:00
@using ImageBoardServerApp.Auth
@using ImageBoardServerApp.Data.Repository
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<PageTitle>YOU - Bulletboards</PageTitle>
2023-02-12 18:06:33 +00:00
<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>
2023-02-12 18:06:33 +00:00
<br/>
<a href="/sys/logout">[Logout]</a>
2023-02-12 18:06:33 +00:00
</Authorized>
<NotAuthorized>
<span>You are not logged in.</span>
<a class="navbar-brand" href="/sys/login">Please login first.</a>
</NotAuthorized>
</AuthorizeView>
@code {
2023-02-12 18:06:33 +00:00
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));
2023-02-12 18:06:33 +00:00
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);
}
}