2023-02-12 16:01:46 +00:00
|
|
|
@page "/sys/you"
|
2023-02-12 18:06:33 +00:00
|
|
|
@using ImageBoardServerApp.Auth
|
|
|
|
@using ImageBoardServerApp.Data.Repository
|
|
|
|
@inject AuthenticationStateProvider authStateProvider
|
|
|
|
@inject NavigationManager navManager
|
2023-02-12 16:01:46 +00:00
|
|
|
|
2023-06-08 21:34:59 +00:00
|
|
|
<PageTitle>YOU - Bulletboards</PageTitle>
|
|
|
|
|
2023-02-12 18:06:33 +00:00
|
|
|
<AuthorizeView>
|
|
|
|
<Authorized>
|
2023-06-12 18:46:44 +00:00
|
|
|
<h3>YOUR ACCOUNT</h3>
|
2023-02-12 18:06:33 +00:00
|
|
|
<br/>
|
2023-06-12 19:22:44 +00:00
|
|
|
<span>Email: @userid</span>
|
2023-02-12 18:06:33 +00:00
|
|
|
<br/>
|
2023-06-12 18:46:44 +00:00
|
|
|
<form>
|
|
|
|
<RadzenFormField Text="Enter new email address" Variant="Variant.Outlined">
|
|
|
|
<RadzenTextBox @bind-Value="@newMail"/>
|
|
|
|
</RadzenFormField>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
2023-06-12 19:22:44 +00:00
|
|
|
<RadzenButton Click=@changeEmail Text="Set Email" ButtonStyle="ButtonStyle.Secondary"/>
|
2023-06-12 18:46:44 +00:00
|
|
|
<br/>
|
|
|
|
</form>
|
|
|
|
@if (msg != null)
|
|
|
|
{
|
|
|
|
<div>
|
|
|
|
<span class="msg">@msg</span>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<br/>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
|
|
|
<a href="/sys/resetpw">[Click here to change your password]</a>
|
2023-02-12 18:06:33 +00:00
|
|
|
<br/>
|
|
|
|
<br/>
|
2023-06-08 21:34:59 +00:00
|
|
|
<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>
|
2023-02-13 17:45:14 +00:00
|
|
|
|
2023-02-12 16:01:46 +00:00
|
|
|
@code {
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-06-12 18:46:44 +00:00
|
|
|
private string userid { get; set; } = "";
|
2023-02-12 18:06:33 +00:00
|
|
|
private string newMail { get; set; }
|
2023-06-12 18:46:44 +00:00
|
|
|
private string msg { get; set; }
|
|
|
|
|
|
|
|
private UserData u { get; set; }
|
|
|
|
private string isMailConfirmedMsg { get; set; }
|
2023-02-12 18:06:33 +00:00
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
{
|
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
if (user.User.Identity.IsAuthenticated)
|
|
|
|
{
|
2023-06-12 18:46:44 +00:00
|
|
|
userid = user.User.Identity.Name;
|
2023-02-12 18:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-02-12 18:06:33 +00:00
|
|
|
private async Task changeEmail()
|
|
|
|
{
|
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
var usr = user.User;
|
2023-06-12 18:46:44 +00:00
|
|
|
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
2023-02-12 18:06:33 +00:00
|
|
|
if (foundusr == null)
|
|
|
|
{
|
2023-06-12 18:46:44 +00:00
|
|
|
msg = "Could not find user.";
|
2023-02-12 18:06:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-06-12 18:46:44 +00:00
|
|
|
if (newMail == null || newMail == "" || !newMail.Contains("@") || !newMail.Contains("."))
|
2023-02-12 18:06:33 +00:00
|
|
|
{
|
2023-06-12 18:46:44 +00:00
|
|
|
msg = "The new email is not valid.";
|
2023-02-12 18:06:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-06-12 19:22:44 +00:00
|
|
|
UserData u2 = await UsersRepository.getUserByEmailRawAsync(newMail);
|
|
|
|
if (u2 != null)
|
|
|
|
{
|
|
|
|
msg = "This email is already in use.";
|
|
|
|
return;
|
|
|
|
}
|
2023-02-12 18:06:33 +00:00
|
|
|
foundusr.Email = newMail;
|
|
|
|
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
2023-06-12 18:46:44 +00:00
|
|
|
foundusr.ConfirmedEmail = false;
|
2023-02-12 18:06:33 +00:00
|
|
|
await UsersRepository.updateUserAsync(foundusr);
|
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-06-12 18:46:44 +00:00
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
{
|
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
var usr = user.User;
|
|
|
|
u = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
|
|
|
isMailConfirmedMsg = u.ConfirmedEmail ? "Email is confirmed" : "Email is NOT confirmed";
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
|
|
}
|
|
|
|
|
2023-02-12 16:01:46 +00:00
|
|
|
}
|