bulletboards/ImageBoardServerApp/Pages/Accounts/Login.razor
limited_dev 8f38879294 feat: made accounts deleteable, other changes
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
2023-06-13 16:24:38 +02:00

54 lines
No EOL
1.7 KiB
Text

@page "/sys/login"
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@inject IJSRuntime js
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<PageTitle>Login - BulletBoards</PageTitle>
<h3 class="headLogin">Login to Bulletboards</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=@login Text="login" ButtonStyle="ButtonStyle.Secondary"/>
<br/>
</form>
</div>
<a href="/sys/resetpw">Reset Password</a>
@code {
private bool verified;
public string Email { get; set; }
public string Password { get; set; }
private async Task login()
{
var user = await UsersRepository.getUserByEmailRawAsync(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)
{
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
navManager.NavigateTo("/", true);
return;
}
await js.InvokeVoidAsync("alert", $"Wrong Password");
}
}