feat: made accounts deleteable, other changes

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-13 16:24:38 +02:00
parent c20c5c9343
commit 8f38879294
10 changed files with 116 additions and 35 deletions

View file

@ -0,0 +1,57 @@
@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");
}
}

View file

@ -5,7 +5,7 @@
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<PageTitle>Login - Bulletboards</PageTitle>
<PageTitle>Login - BulletBoards</PageTitle>
<h3 class="headLogin">Login to Bulletboards</h3>
<div class="login">
<form>
@ -25,8 +25,6 @@
<a href="/sys/resetpw">Reset Password</a>
@code {
private Variant vari = Variant.Outlined;
private bool verified;
public string Email { get; set; }

View file

@ -40,6 +40,9 @@
<br/>
<br/>
<a href="/sys/logout">[Logout]</a>
<br/>
<br/>
<a href="/sys/delacc">[Delete Account]</a>
</Authorized>
<NotAuthorized>