From 37512d3f16ac193a416383d0f4caefd5953b888d Mon Sep 17 00:00:00 2001 From: Nana Antwi Date: Sun, 4 Jun 2023 19:55:54 +0000 Subject: [PATCH 1/3] Added validation to login form --- Client/Biskilog Accounting.Client.csproj | 6 ++++ Client/Pages/Auth/Login.razor | 4 +++ Client/Properties/launchSettings.json | 10 +++--- Server/Biskilog Accounting.Server.csproj | 2 ++ Server/Properties/launchSettings.json | 40 ++++++++++++------------ Shared/ClientContractModels/Userauth.cs | 3 ++ 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/Client/Biskilog Accounting.Client.csproj b/Client/Biskilog Accounting.Client.csproj index f344a0f..39d8fb6 100644 --- a/Client/Biskilog Accounting.Client.csproj +++ b/Client/Biskilog Accounting.Client.csproj @@ -8,6 +8,12 @@ $(AssemblyName.Replace(' ', '_')) + + true + + + true + diff --git a/Client/Pages/Auth/Login.razor b/Client/Pages/Auth/Login.razor index 96af7a1..96965ec 100644 --- a/Client/Pages/Auth/Login.razor +++ b/Client/Pages/Auth/Login.razor @@ -81,15 +81,19 @@

Please login to your account

+ +
+
+
diff --git a/Client/Properties/launchSettings.json b/Client/Properties/launchSettings.json index 62cae75..94bcda6 100644 --- a/Client/Properties/launchSettings.json +++ b/Client/Properties/launchSettings.json @@ -8,23 +8,23 @@ "profiles": { "http": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "applicationUrl": "http://localhost:5136", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true }, "https": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "applicationUrl": "https://localhost:7247;http://localhost:5136", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true }, "IIS Express": { "commandName": "IISExpress", @@ -35,4 +35,4 @@ } } } -} +} \ No newline at end of file diff --git a/Server/Biskilog Accounting.Server.csproj b/Server/Biskilog Accounting.Server.csproj index 02e123a..6357be7 100644 --- a/Server/Biskilog Accounting.Server.csproj +++ b/Server/Biskilog Accounting.Server.csproj @@ -8,6 +8,8 @@ $(AssemblyName.Replace(' ', '_')) + + diff --git a/Server/Properties/launchSettings.json b/Server/Properties/launchSettings.json index 5e250c1..6bad409 100644 --- a/Server/Properties/launchSettings.json +++ b/Server/Properties/launchSettings.json @@ -1,44 +1,44 @@ { + "iisExpress": { + "applicationUrl": "http://localhost:24369", + "sslPort": 44366 + }, + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:54487/", + "sslPort": 44383 + } + }, "profiles": { "http": { "commandName": "Project", "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "http://localhost:5136", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "dotnetRunMessages": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "http://localhost:5136" + "dotnetRunMessages": true }, "https": { "commandName": "Project", "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:7247;http://localhost:5136", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "dotnetRunMessages": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:7247;http://localhost:5136" + "dotnetRunMessages": true }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}" - } - }, - "iisExpress": { - "applicationUrl": "http://localhost:24369", - "sslPort": 44366 - }, - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:54487/", - "sslPort": 44383 + } } } } \ No newline at end of file diff --git a/Shared/ClientContractModels/Userauth.cs b/Shared/ClientContractModels/Userauth.cs index d8b010a..bcf8334 100644 --- a/Shared/ClientContractModels/Userauth.cs +++ b/Shared/ClientContractModels/Userauth.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace Biskilog_Accounting.Shared.ClientContractModels; @@ -9,10 +10,12 @@ public partial class Userauth public int ClientId { get; set; } + [Required(ErrorMessage = "Invalid username")] public string? Username { get; set; } public string? Email { get; set; } + [Required(ErrorMessage = "Invalid password")] public string? Passsword { get; set; } public string? PhoneNumber { get; set; } -- 2.25.1 From 14643333e6016410585a8d1568ab4e58cc31e50c Mon Sep 17 00:00:00 2001 From: Nana Antwi Date: Sun, 4 Jun 2023 22:45:55 +0000 Subject: [PATCH 2/3] Added update to validation --- Client/Pages/Auth/Login.razor | 16 +++++++++++++--- Client/Pages/Auth/Login.razor.cs | 23 ++++++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Client/Pages/Auth/Login.razor b/Client/Pages/Auth/Login.razor index 96965ec..0a7aa13 100644 --- a/Client/Pages/Auth/Login.razor +++ b/Client/Pages/Auth/Login.razor @@ -81,19 +81,29 @@

Please login to your account

- +
- + @if (showUsernameError) + { +

Enter valid Uaername

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

Enter valid Password

+ + } +
diff --git a/Client/Pages/Auth/Login.razor.cs b/Client/Pages/Auth/Login.razor.cs index 0918a07..2c512f9 100644 --- a/Client/Pages/Auth/Login.razor.cs +++ b/Client/Pages/Auth/Login.razor.cs @@ -10,8 +10,10 @@ namespace Biskilog_Accounting.Client.Pages.Auth public partial class Login { private string m_email, m_password; + private bool showUsernameError, showPasswordError; private bool m_remember { get; set; } protected bool IsVisible { get; set; } + //NotificationMessage notificationMessage = new NotificationMessage(); private Userauth authenticatedUser; /// @@ -45,14 +47,23 @@ namespace Biskilog_Accounting.Client.Pages.Auth var responseMain = await m_http.PostAsJsonAsync("api/authentication/type-a", authenticatedUser); if (responseMain.IsSuccessStatusCode) { - string token = await responseMain.Content.ReadAsStringAsync(); - await m_tokenService.SetToken(token, m_remember); + 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); + + var authHeader = new AuthenticationHeaderValue("Bearer", token); + m_http.DefaultRequestHeaders.Authorization = authHeader; - 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) { } @@ -108,5 +119,7 @@ namespace Biskilog_Accounting.Client.Pages.Auth m_password = value; StateHasChanged(); } + + } } \ No newline at end of file -- 2.25.1 From 489d1f46c059928d1028c1c9ba665a582215c6c4 Mon Sep 17 00:00:00 2001 From: Nana Antwi Date: Sun, 4 Jun 2023 23:33:25 +0000 Subject: [PATCH 3/3] 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 -- 2.25.1