bulletboards/ImageBoardServerApp/Pages/Accounts/DeleteAccount.razor

57 lines
1.8 KiB
Text
Raw Permalink Normal View History

@page "/sys/delacc"
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@inject IJSRuntime js
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<PageTitle>Delete your account - BulletBoards</PageTitle>
<h3 class="headLogin">Delete your account</h3>
<div class="login">
<form>
<RadzenFormField Text="Email" Variant="Variant.Outlined">
<RadzenTextBox @bind-Value="@Email"/>
</RadzenFormField>
<br/>
<RadzenFormField Text="Password" Variant="Variant.Outlined">
<RadzenPassword @bind-Value="@Password"/>
</RadzenFormField>
<br/>
<br/>
<RadzenButton Click=@del Text="delete account" ButtonStyle="ButtonStyle.Secondary"/>
<br/>
</form>
</div>
@code {
private bool verified;
public string Email { get; set; }
public string Password { get; set; }
private async void del()
{
var user = await UsersRepository.getUserByEmailAsync(Email);
if (user == null)
{
await js.InvokeVoidAsync("alert", "User does not exist");
verified = false;
return;
}
Console.WriteLine("loggin you in...");
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
if (verified)
{
await CommentsRepository.deleteCommentFromUser(user);
await PostsRepository.deletePostsFromUser(user);
await UsersRepository.deleteUserAsync(user.UserID);
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
navManager.NavigateTo("/", true);
return;
}
await js.InvokeVoidAsync("alert", $"Wrong Password");
}
}