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
|
2023-06-12 21:17:29 +00:00
|
|
|
@using ImageBoardServerApp.Util
|
2023-02-12 18:06:33 +00:00
|
|
|
@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 21:17:29 +00:00
|
|
|
@if (isMailConfirmedMsg != null)
|
|
|
|
{
|
|
|
|
<span>@isMailConfirmedMsg</span>
|
|
|
|
<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 21:17:29 +00:00
|
|
|
private string msg { get; set; } = "";
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-06-12 21:17:29 +00:00
|
|
|
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 21:17:29 +00:00
|
|
|
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(user.User.Identity.Name);
|
|
|
|
if (foundusr != null)
|
|
|
|
isMailConfirmedMsg = foundusr.ConfirmedEmail ? "Email is confirmed" : "Email is NOT confirmed";
|
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()
|
|
|
|
{
|
2023-06-12 21:17:29 +00:00
|
|
|
msg = "Checking...";
|
2023-02-12 18:06:33 +00:00
|
|
|
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 21:17:29 +00:00
|
|
|
|
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-06-12 21:17:29 +00:00
|
|
|
|
|
|
|
msg = "Generating...";
|
|
|
|
var hash = TheManager.getmd5Hash();
|
|
|
|
|
2023-02-12 18:06:33 +00:00
|
|
|
foundusr.Email = newMail;
|
2023-06-12 21:17:29 +00:00
|
|
|
foundusr.ConfirmEmailToken = hash;
|
2023-02-12 18:06:33 +00:00
|
|
|
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 21:17:29 +00:00
|
|
|
Postman.sendMail(newMail,
|
|
|
|
"Confirm email",
|
|
|
|
"Confirm you email:\n" +
|
|
|
|
$"https://bulletboards.xyz/sys/click/confirmmail/{foundusr.UserID}/{foundusr.Email}/{newMail}/{hash}");
|
|
|
|
|
|
|
|
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(foundusr);
|
|
|
|
navManager.NavigateTo("/sys/you", true, true);
|
2023-06-12 18:46:44 +00:00
|
|
|
}
|
|
|
|
|
2023-02-12 16:01:46 +00:00
|
|
|
}
|