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.
82 lines
2.7 KiB
Plaintext
82 lines
2.7 KiB
Plaintext
@using KWWebInvApp.Data
|
|
@inject UserServices userService
|
|
@inject IDialogService DialogService
|
|
@inject NavigationManager navigationManager
|
|
|
|
<EditForm Model="@userAttemtingToLogin" 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"
|
|
@bind-Value="userAttemtingToLogin.username" />
|
|
|
|
<MudTextField T="string" Label="Password"
|
|
InputType="InputType.Password"
|
|
@bind-Value="pass" />
|
|
<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? pass, error, submitButtonText = "Login";
|
|
UserInfoServices.userinfo userAttemtingToLogin = new();
|
|
|
|
//protected override async Task OnInitializedAsync()
|
|
//{
|
|
|
|
//}
|
|
|
|
async Task SubmitLogin()
|
|
{
|
|
error = null;
|
|
|
|
if (String.IsNullOrEmpty(userAttemtingToLogin.username) || String.IsNullOrEmpty(pass))
|
|
{
|
|
error = "Username and Password is required";
|
|
return;
|
|
}
|
|
|
|
UserInfoServices.UserInfoServiceClient userInfoServiceClient = new();
|
|
|
|
waitingButton(true);
|
|
userAttemtingToLogin.pass = await userInfoServiceClient.md5EncodingAsync(pass);
|
|
userService.CurrentUser = await userInfoServiceClient.AuthenticateUserAsync(userAttemtingToLogin);
|
|
waitingButton();
|
|
|
|
if (userService.CurrentUser == null)
|
|
error = "Invalid Username or Password";
|
|
else
|
|
navigationManager.NavigateTo("/");
|
|
}
|
|
|
|
void waitingButton(bool waiting = false)
|
|
{
|
|
if(waiting)
|
|
{
|
|
submitButtonDisabled = true;
|
|
submitButtonText = "Please Wait...";
|
|
}
|
|
else
|
|
{
|
|
submitButtonDisabled = false;
|
|
submitButtonText = "Login";
|
|
}
|
|
}
|
|
}
|