bulletboards/ImageBoardServerApp/Pages/Accounts/Login.razor

70 lines
2.4 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>
2023-05-15 07:55:56 +00:00
<RadzenTemplateForm TItem="Model" Data="model" Submit=@login>
<RadzenStack Gap="1rem" Class="gapeing">
<RadzenFormField Text="Email" Variant="@vari">
<ChildContent>
<RadzenTextBox Name="Email" @bind-Value=@model.Email />
</ChildContent>
<Helper>
<RadzenRequiredValidator Component="Email" Text="First name is required." />
</Helper>
</RadzenFormField>
<RadzenFormField Text="Password" Variant="@vari">
<ChildContent>
<RadzenTextBox Name="Password" @bind-Value=@model.Password />
</ChildContent>
<Helper>
<RadzenRequiredValidator Component="Password" Text="Your Password" />
</Helper>
</RadzenFormField>
<RadzenButton ButtonType="ButtonType.Submit" Text="Login" ></RadzenButton>
</RadzenStack>
</RadzenTemplateForm>
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
class Model
{
public string Email { get; set; }
public string Password { get; set; }
}
Model model = new Model();
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...");
2023-05-15 07:55:56 +00:00
var user = await UsersRepository.getUserByEmailRawAsync(model.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;
}
2023-05-15 07:55:56 +00:00
verified = BCrypt.Net.BCrypt.Verify(model.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
}
}