@page "/login"
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@using System.Runtime.InteropServices
@inject IJSRuntime js
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
Login to bulletbroards
@code {
private string Email { get; set; }
private string Password { get; set; }
private bool verified;
private async Task login()
{
Console.WriteLine("loggin you in...");
var user = await UsersRepository.getUserByEmailAsync(Email);
if (user == null)
{
await js.InvokeVoidAsync("alert", "User does not exist");
verified = false;
return;
}
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
if (verified)
{
verified = true;
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
navManager.NavigateTo("/", true);
return;
}
await js.InvokeVoidAsync("alert", $"Wrong Password");
}
}