@page "/sys/you"
@using ImageBoardServerApp.Auth
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Util
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
YOU - Bulletboards
YOUR ACCOUNT
Email: @userid
@if (isMailConfirmedMsg != null)
{
@isMailConfirmedMsg
}
@if (msg != null)
{
@msg
}
[Click here to change your password]
[Logout]
[Delete Account]
You are not logged in.
Please login first.
@code {
private string userid { get; set; } = "";
private string newMail { get; set; }
private string msg { get; set; } = "";
private string isMailConfirmedMsg { get; set; } = "";
protected override async Task OnInitializedAsync()
{
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
var user = await cauthStateProvder.GetAuthenticationStateAsync();
if (user.User.Identity.IsAuthenticated)
{
userid = user.User.Identity.Name;
}
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(user.User.Identity.Name);
if (foundusr != null)
isMailConfirmedMsg = foundusr.ConfirmedEmail ? "Email is confirmed" : "Email is NOT confirmed";
}
private async Task changeEmail()
{
msg = "Checking...";
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
var user = await cauthStateProvder.GetAuthenticationStateAsync();
var usr = user.User;
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
if (foundusr == null)
{
msg = "Could not find user.";
return;
}
if (newMail == null || newMail == "" || !newMail.Contains("@") || !newMail.Contains("."))
{
msg = "The new email is not valid.";
return;
}
UserData u2 = await UsersRepository.getUserByEmailRawAsync(newMail);
if (u2 != null)
{
msg = "This email is already in use.";
return;
}
msg = "Generating...";
var hash = TheManager.getmd5Hash();
foundusr.Email = newMail;
foundusr.ConfirmEmailToken = hash;
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
foundusr.ConfirmedEmail = false;
await UsersRepository.updateUserAsync(foundusr);
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);
}
}