From 489d1f46c059928d1028c1c9ba665a582215c6c4 Mon Sep 17 00:00:00 2001 From: Nana Antwi Date: Sun, 4 Jun 2023 23:33:25 +0000 Subject: [PATCH] Added latest validation update --- Client/Pages/Auth/Login.razor | 14 ++++++------- Client/Pages/Auth/Login.razor.cs | 36 ++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Client/Pages/Auth/Login.razor b/Client/Pages/Auth/Login.razor index 0a7aa13..b456c32 100644 --- a/Client/Pages/Auth/Login.razor +++ b/Client/Pages/Auth/Login.razor @@ -87,21 +87,19 @@ - @if (showUsernameError) - { -

Enter valid Uaername

- } - + @if (!validStatus) + { +

@errormeaasge("invalid")

+ }
- @if (showPasswordError) + @if (!validStatus) { -

Enter valid Password

- +

@errormeaasge("invalid")

}
diff --git a/Client/Pages/Auth/Login.razor.cs b/Client/Pages/Auth/Login.razor.cs index 2c512f9..2736d42 100644 --- a/Client/Pages/Auth/Login.razor.cs +++ b/Client/Pages/Auth/Login.razor.cs @@ -13,6 +13,7 @@ namespace Biskilog_Accounting.Client.Pages.Auth private bool showUsernameError, showPasswordError; private bool m_remember { get; set; } protected bool IsVisible { get; set; } + public bool validStatus = false; //NotificationMessage notificationMessage = new NotificationMessage(); private Userauth authenticatedUser; @@ -47,28 +48,26 @@ namespace Biskilog_Accounting.Client.Pages.Auth var responseMain = await m_http.PostAsJsonAsync("api/authentication/type-a", authenticatedUser); if (responseMain.IsSuccessStatusCode) { - showUsernameError = string.IsNullOrEmpty(m_email); - showPasswordError = string.IsNullOrEmpty(m_password); - if(!showUsernameError && !showPasswordError) - { - string token = await responseMain.Content.ReadAsStringAsync(); - await m_tokenService.SetToken(token, m_remember); + validStatus = true; - var authHeader = new AuthenticationHeaderValue("Bearer", token); - m_http.DefaultRequestHeaders.Authorization = authHeader; + string token = await responseMain.Content.ReadAsStringAsync(); + await m_tokenService.SetToken(token, m_remember); + + var authHeader = new AuthenticationHeaderValue("Bearer", token); + m_http.DefaultRequestHeaders.Authorization = authHeader; + + m_navigationManager.NavigateTo("/"); - m_navigationManager.NavigateTo("/"); - } } - + else if (responseMain.StatusCode == System.Net.HttpStatusCode.BadRequest) { } } - catch (Exception ex) + catch (Exception ex) { Console.WriteLine(ex.ToString()); } @@ -120,6 +119,17 @@ namespace Biskilog_Accounting.Client.Pages.Auth StateHasChanged(); } - + public string errormeaasge(string message) + { + showPasswordError = string.IsNullOrEmpty(m_email); + showUsernameError = string.IsNullOrEmpty(m_password); + + if (showUsernameError && showPasswordError) + { + message = ""; + } + return message; + + } } } \ No newline at end of file