You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.1 KiB
Plaintext
86 lines
3.1 KiB
Plaintext
@page "/userlogin"
|
|
@using KWWebInvApp.Data;
|
|
@using KWWebInvApp.Services;
|
|
@using Microsoft.AspNetCore.WebUtilities;
|
|
|
|
@inject IAuthenticationService AuthenticationStateService
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<PageTitle>User Login</PageTitle>
|
|
<MudText Typo="Typo.h3" GutterBottom="true">Enter your credential for verification</MudText>
|
|
|
|
<EditForm Model="@loginData" OnValidSubmit="SubmitLogin">
|
|
<MudGrid>
|
|
<MudItem sm="12">
|
|
<MudCard>
|
|
<MudCardContent>
|
|
<MudText Typo="Typo.h4">Login</MudText>
|
|
<MudText Typo="Typo.subtitle1">Welcome to Merchandise and SAC System</MudText>
|
|
@if (error != null)
|
|
{
|
|
<MudAlert Severity="Severity.Error">@error</MudAlert>
|
|
}
|
|
<MudTextField T="string" Label="Username" Required="true" RequiredError="Username is required"
|
|
@bind-Value="loginData.username" />
|
|
|
|
<MudTextField T="string" Label="Password" Required="true" RequiredError="Password is required"
|
|
InputType="InputType.Password"
|
|
@bind-Value="loginData.password" />
|
|
<MudCardActions Class="mt-5">
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" ButtonType="ButtonType.Submit" Disabled="submitButtonDisabled">@submitButtonText</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="mx-2" ButtonType="ButtonType.Reset" Disabled="submitButtonDisabled">Reset</MudButton>
|
|
</MudCardActions>
|
|
</MudCardContent>
|
|
</MudCard>
|
|
</MudItem>
|
|
</MudGrid>
|
|
</EditForm>
|
|
|
|
@code {
|
|
bool submitButtonDisabled = false;
|
|
string? error, submitButtonText = "Login";
|
|
LoginData loginData = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
|
|
}
|
|
|
|
async Task SubmitLogin()
|
|
{
|
|
error = null;
|
|
|
|
waitingButton(true);
|
|
var webAuthenticationStateProvider = (WebAuthenticationStateProvider)AuthenticationStateProvider;
|
|
var loginSuccess = await webAuthenticationStateProvider.LoginAsync(loginData);
|
|
|
|
if (loginSuccess)
|
|
{
|
|
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
|
|
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("returnUrl", out var returnURL))
|
|
NavigationManager.NavigateTo($"/{returnURL}");
|
|
else
|
|
NavigationManager.NavigateTo("/");
|
|
}
|
|
else
|
|
error = "Invalid username or password. Please try again.";
|
|
|
|
waitingButton(false);
|
|
}
|
|
|
|
void waitingButton(bool waiting = false)
|
|
{
|
|
if(waiting)
|
|
{
|
|
submitButtonDisabled = true;
|
|
submitButtonText = "Please Wait...";
|
|
}
|
|
else
|
|
{
|
|
submitButtonDisabled = false;
|
|
submitButtonText = "Login";
|
|
}
|
|
}
|
|
}
|