chore: cleanup
This commit is contained in:
parent
0e725b065a
commit
f5ac34e639
17 changed files with 67 additions and 3 deletions
51
ImageBoardServerApp/Pages/Accounts/Login.razor
Normal file
51
ImageBoardServerApp/Pages/Accounts/Login.razor
Normal file
|
@ -0,0 +1,51 @@
|
|||
@page "/login"
|
||||
@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>
|
||||
<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>
|
||||
<a @onclick="login" href="javascript:void(0)">[Login]</a>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
@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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue