bulletboards/ImageBoardServerApp/Pages/Accounts/Login.razor

54 lines
1.6 KiB
Text
Raw Normal View History

@page "/sys/login"
2023-01-19 12:00:30 +00:00
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@inject IJSRuntime js
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
2023-05-15 07:55:56 +00:00
<h3 class="headLogin">Login to bulletbroards</h3>
<div class="login">
2023-01-19 12:00:30 +00:00
<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" />
2023-01-19 12:00:30 +00:00
</form>
</div>
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
private bool verified;
2023-05-15 07:55:56 +00:00
public string Email { get; set; }
public string Password { get; set; }
2023-01-19 12:00:30 +00:00
private async Task login()
2023-01-19 12:00:30 +00:00
{
Console.WriteLine("loggin you in...");
var user = await UsersRepository.getUserByEmailRawAsync(Email);
if (user == null)
2023-01-19 12:00:30 +00:00
{
await js.InvokeVoidAsync("alert", "User does not exist");
2023-01-19 12:00:30 +00:00
verified = false;
return;
}
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
2023-01-19 12:00:30 +00:00
if (verified)
{
verified = true;
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
navManager.NavigateTo("/", true);
2023-01-19 12:00:30 +00:00
return;
}
await js.InvokeVoidAsync("alert", $"Wrong Password");
2023-01-19 12:00:30 +00:00
}
}