bulletboards/ImageBoardServerApp/Pages/Login.razor

57 lines
1.7 KiB
Text
Raw Normal View History

@page "/login"
2023-01-19 12:00:30 +00:00
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@using System.Runtime.InteropServices
@inject IJSRuntime js
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<h3>Login to bulletbroards</h3>
2023-01-19 12:00:30 +00:00
<div>
<form>
<div>
<label for="email">Email:</label>
<input type="email" id="email" @bind="Email" />
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" @bind="Password" />
</div>
2023-02-02 07:15:43 +00:00
<a @onclick="login" href="javascript:void(0)">[Login]</a>
2023-01-19 12:00:30 +00:00
</form>
2023-01-19 12:00:30 +00:00
</div>
@code {
private string Email { get; set; }
private string Password { get; set; }
private bool verified;
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.getUserByEmailAsync(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 creds:\n{BCrypt.Net.BCrypt.HashPassword(Password)}");
2023-01-19 12:00:30 +00:00
}
/*
*
UserData target = (await UsersRepository.getUserByEmailAsync(Email));
*/
2023-01-19 12:00:30 +00:00
}