PCRB follow up client side logic
This commit is contained in:
53
MesaFabApproval.Client/Pages/Login.razor.cs
Normal file
53
MesaFabApproval.Client/Pages/Login.razor.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
using MudBlazor;
|
||||
|
||||
namespace MesaFabApproval.Client.Pages;
|
||||
|
||||
public partial class Login {
|
||||
[Inject] NavigationManager navigationManager { get; set; }
|
||||
[Inject] IMemoryCache cache { get; set; }
|
||||
|
||||
public string? _redirectPath { get; set; }
|
||||
private bool success;
|
||||
private bool processing = false;
|
||||
private string[] errors = { };
|
||||
private string? username;
|
||||
private string? password;
|
||||
|
||||
protected override async Task OnParametersSetAsync() {
|
||||
Uri uri = navigationManager.ToAbsoluteUri(navigationManager.Uri);
|
||||
|
||||
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("redirectPath", out var redirectPath)) {
|
||||
_redirectPath = System.Net.WebUtility.UrlDecode(redirectPath);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_redirectPath)) {
|
||||
_redirectPath = cache.Get<string>("redirectUrl");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SubmitLogin() {
|
||||
processing = true;
|
||||
if (string.IsNullOrWhiteSpace(username)) snackbar.Add("Username is required!", Severity.Error);
|
||||
else if (string.IsNullOrWhiteSpace(password)) snackbar.Add("Password is required!", Severity.Error);
|
||||
else {
|
||||
await authStateProvider.LoginAsync(username, password);
|
||||
if (!string.IsNullOrWhiteSpace(_redirectPath)) {
|
||||
navManager.NavigateTo(_redirectPath);
|
||||
} else {
|
||||
navManager.NavigateTo("dashboard");
|
||||
}
|
||||
}
|
||||
processing = false;
|
||||
}
|
||||
|
||||
private async Task SubmitIfEnter(KeyboardEventArgs e) {
|
||||
if (e.Key == "Enter" && success) {
|
||||
SubmitLogin();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user