Added authenication/authorization. Refactored api startup.
This commit is contained in:
86
JSMR.UI.Blazor/Pages/Login.razor
Normal file
86
JSMR.UI.Blazor/Pages/Login.razor
Normal file
@@ -0,0 +1,86 @@
|
||||
@page "/login"
|
||||
|
||||
@using JSMR.UI.Blazor.Services
|
||||
|
||||
@inject SessionState Session
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<h3>Login</h3>
|
||||
|
||||
@if (Session.IsAuthenticated)
|
||||
{
|
||||
<p>You're already logged in as <b>@Session.Me?.name</b>.</p>
|
||||
<button @onclick="Logout">Logout</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div style="max-width: 360px;">
|
||||
<div>
|
||||
<label>Username</label><br />
|
||||
<input @bind="username" />
|
||||
</div>
|
||||
<div style="margin-top: 8px;">
|
||||
<label>Password</label><br />
|
||||
<input type="password" @bind="password" />
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 12px;">
|
||||
<button @onclick="LoginAsync" disabled="@busy">Login</button>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
<p style="color: crimson; margin-top: 8px;">@error</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string username = "";
|
||||
private string password = "";
|
||||
private bool busy;
|
||||
private string? error;
|
||||
|
||||
private async Task LoginAsync()
|
||||
{
|
||||
busy = true;
|
||||
error = null;
|
||||
try
|
||||
{
|
||||
var ok = await Session.LoginAsync(username, password);
|
||||
if (!ok)
|
||||
{
|
||||
error = "Invalid username or password.";
|
||||
return;
|
||||
}
|
||||
|
||||
Nav.NavigateTo("/");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
busy = true;
|
||||
error = null;
|
||||
try
|
||||
{
|
||||
await Session.LogoutAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
@using JSMR.Application.Common.Search
|
||||
@using JSMR.Application.VoiceWorks.Queries.Search
|
||||
@using JSMR.UI.Blazor.Components
|
||||
@using JSMR.UI.Blazor.Components.Authentication
|
||||
@using JSMR.UI.Blazor.Enums
|
||||
@using JSMR.UI.Blazor.Filters
|
||||
@using JSMR.UI.Blazor.Services
|
||||
@@ -11,6 +12,7 @@
|
||||
|
||||
@inherits SearchPageBase<VoiceWorkFilterState, VoiceWorkSearchResult>
|
||||
|
||||
<RequireAuthentication>
|
||||
<PageTitle>Voice Works</PageTitle>
|
||||
|
||||
<h3>Voice Works</h3>
|
||||
@@ -40,6 +42,7 @@
|
||||
</RightContent>
|
||||
</JPagination>
|
||||
}
|
||||
</RequireAuthentication>
|
||||
|
||||
@code {
|
||||
[Inject]
|
||||
|
||||
Reference in New Issue
Block a user