2023-02-12 16:01:46 +00:00
|
|
|
@page "/sys/login"
|
2023-01-19 12:00:30 +00:00
|
|
|
@using ImageBoardServerApp.Data.Repository
|
2023-02-01 20:49:02 +00:00
|
|
|
@using ImageBoardServerApp.Auth
|
|
|
|
@inject IJSRuntime js
|
|
|
|
@inject AuthenticationStateProvider authStateProvider
|
|
|
|
@inject NavigationManager navManager
|
|
|
|
|
2023-06-08 21:34:59 +00:00
|
|
|
<PageTitle>Login - Bulletboards</PageTitle>
|
|
|
|
<h3 class="headLogin">Login to Bulletboards</h3>
|
2023-05-15 07:55:56 +00:00
|
|
|
<div class="login">
|
2023-01-19 12:00:30 +00:00
|
|
|
<form>
|
2023-05-31 12:13:18 +00:00
|
|
|
<RadzenFormField Text="Email" Variant="Variant.Outlined">
|
2023-06-12 18:46:44 +00:00
|
|
|
<RadzenTextBox @bind-Value="@Email"/>
|
2023-05-31 12:13:18 +00:00
|
|
|
</RadzenFormField>
|
|
|
|
<br/>
|
|
|
|
<RadzenFormField Text="Password" Variant="Variant.Outlined">
|
2023-06-12 18:46:44 +00:00
|
|
|
<RadzenPassword @bind-Value="@Password"/>
|
2023-05-31 12:13:18 +00:00
|
|
|
</RadzenFormField>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
2023-06-12 19:22:44 +00:00
|
|
|
<RadzenButton Click=@login Text="login" ButtonStyle="ButtonStyle.Secondary"/>
|
2023-06-08 21:34:59 +00:00
|
|
|
<br/>
|
2023-01-19 12:00:30 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
2023-06-08 21:34:59 +00:00
|
|
|
<a href="/sys/resetpw">Reset Password</a>
|
2023-02-11 22:04:02 +00:00
|
|
|
|
2023-01-19 12:00:30 +00:00
|
|
|
@code {
|
2023-05-15 07:55:56 +00:00
|
|
|
private Variant vari = Variant.Outlined;
|
2023-01-19 12:00:30 +00:00
|
|
|
|
2023-02-01 20:49:02 +00:00
|
|
|
private bool verified;
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-05-31 12:13:18 +00:00
|
|
|
public string Email { get; set; }
|
|
|
|
public string Password { get; set; }
|
2023-01-19 12:00:30 +00:00
|
|
|
|
2023-02-01 20:49:02 +00:00
|
|
|
private async Task login()
|
2023-01-19 12:00:30 +00:00
|
|
|
{
|
2023-05-31 12:13:18 +00:00
|
|
|
var user = await UsersRepository.getUserByEmailRawAsync(Email);
|
2023-02-01 20:49:02 +00:00
|
|
|
if (user == null)
|
2023-01-19 12:00:30 +00:00
|
|
|
{
|
2023-02-01 20:49:02 +00:00
|
|
|
await js.InvokeVoidAsync("alert", "User does not exist");
|
2023-01-19 12:00:30 +00:00
|
|
|
verified = false;
|
|
|
|
return;
|
|
|
|
}
|
2023-06-12 18:46:44 +00:00
|
|
|
Console.WriteLine("loggin you in...");
|
2023-05-31 12:13:18 +00:00
|
|
|
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
|
2023-01-19 12:00:30 +00:00
|
|
|
if (verified)
|
|
|
|
{
|
2023-02-01 20:49:02 +00:00
|
|
|
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
|
|
|
|
navManager.NavigateTo("/", true);
|
2023-01-19 12:00:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-02-02 17:50:50 +00:00
|
|
|
await js.InvokeVoidAsync("alert", $"Wrong Password");
|
2023-01-19 12:00:30 +00:00
|
|
|
}
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-01-19 12:00:30 +00:00
|
|
|
}
|