change the protection to authorize view tags
change the protection to authorize view tagspull/2/head
parent
ae687b1cf4
commit
2ab9eb1160
@ -0,0 +1,85 @@
|
|||||||
|
@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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,81 +0,0 @@
|
|||||||
@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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,34 @@
|
|||||||
|
@using KWWebInvApp.Data
|
||||||
|
@using KWWebInvApp.Services;
|
||||||
|
|
||||||
|
@inject NavigationManager navigationManager
|
||||||
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||||
|
|
||||||
|
@code {
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
//var returnUrl = Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||||
|
|
||||||
|
//if (string.IsNullOrWhiteSpace(returnUrl))
|
||||||
|
// Navigation.NavigateTo("/userlogin", true);
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// if (returnUrl == "userlogin")
|
||||||
|
// Navigation.NavigateTo("/userlogin", true);
|
||||||
|
// else
|
||||||
|
// Navigation.NavigateTo($"/userlogin?returnUrl={returnUrl}", true);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAfterRender(bool firstRender)
|
||||||
|
{
|
||||||
|
base.OnAfterRender(firstRender);
|
||||||
|
|
||||||
|
var returnUrl = navigationManager.ToBaseRelativePath(navigationManager.Uri);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(returnUrl))
|
||||||
|
navigationManager.NavigateTo("/userlogin", true);
|
||||||
|
else
|
||||||
|
navigationManager.NavigateTo($"/userlogin?returnUrl={returnUrl}", true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue