WIP: Added validation to login form #9

Open
collins wants to merge 4 commits from BISKI2023-18 into dev
  1. 6
      Client/Biskilog Accounting.Client.csproj
  2. 12
      Client/Pages/Auth/Login.razor
  3. 25
      Client/Pages/Auth/Login.razor.cs
  4. 10
      Client/Properties/launchSettings.json
  5. 2
      Server/Biskilog Accounting.Server.csproj
  6. 40
      Server/Properties/launchSettings.json
  7. 3
      Shared/ClientContractModels/Userauth.cs

6
Client/Biskilog Accounting.Client.csproj

@ -8,6 +8,12 @@
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName> <AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' ">
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' ">
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" /> <None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup> </ItemGroup>

12
Client/Pages/Auth/Login.razor

@ -81,15 +81,27 @@
<form> <form>
<p>Please login to your account</p> <p>Please login to your account</p>
<div class="form-outline mb-4"> <div class="form-outline mb-4">
<input type="email" id="form2Example11" class="form-control" <input type="email" id="form2Example11" class="form-control"
placeholder="Phone number or email address" @oninput="@(args => usernameInput(args.Value.ToString()))" @onkeydown="@Enter" /> placeholder="Phone number or email address" @oninput="@(args => usernameInput(args.Value.ToString()))" @onkeydown="@Enter" />
<label class="form-label" for="form2Example11">Username</label> <label class="form-label" for="form2Example11">Username</label>
@if (!validStatus)
{
<p class="text-danger">@errormeaasge("invalid")</p>
}
</div> </div>
<div class="form-outline mb-4"> <div class="form-outline mb-4">
<input type="password" id="form2Example22" class="form-control" @oninput="@(args => passwordInput(args.Value.ToString()))" @onkeydown="@Enter" /> <input type="password" id="form2Example22" class="form-control" @oninput="@(args => passwordInput(args.Value.ToString()))" @onkeydown="@Enter" />
<label class="form-label" for="form2Example22">Password</label> <label class="form-label" for="form2Example22">Password</label>
@if (!validStatus)
{
<p class="text-danger">@errormeaasge("invalid")</p>
}
</div> </div>
<div class="text-center pt-1 mb-5 pb-1"> <div class="text-center pt-1 mb-5 pb-1">

25
Client/Pages/Auth/Login.razor.cs

@ -10,8 +10,11 @@ namespace Biskilog_Accounting.Client.Pages.Auth
public partial class Login public partial class Login
{ {
private string m_email, m_password; private string m_email, m_password;
private bool showUsernameError, showPasswordError;
Review

please use m_variableName when creating member variables

please use m_variableName when creating member variables
private bool m_remember { get; set; } private bool m_remember { get; set; }
protected bool IsVisible { get; set; } protected bool IsVisible { get; set; }
public bool validStatus = false;
Review

@collins please start public variables with capital letters

@collins please start public variables with capital letters
//NotificationMessage notificationMessage = new NotificationMessage(); //NotificationMessage notificationMessage = new NotificationMessage();
private Userauth authenticatedUser; private Userauth authenticatedUser;
/// <summary> /// <summary>
@ -45,6 +48,9 @@ namespace Biskilog_Accounting.Client.Pages.Auth
var responseMain = await m_http.PostAsJsonAsync("api/authentication/type-a", authenticatedUser); var responseMain = await m_http.PostAsJsonAsync("api/authentication/type-a", authenticatedUser);
if (responseMain.IsSuccessStatusCode) if (responseMain.IsSuccessStatusCode)
{ {
validStatus = true;
string token = await responseMain.Content.ReadAsStringAsync(); string token = await responseMain.Content.ReadAsStringAsync();
await m_tokenService.SetToken(token, m_remember); await m_tokenService.SetToken(token, m_remember);
@ -52,12 +58,16 @@ namespace Biskilog_Accounting.Client.Pages.Auth
m_http.DefaultRequestHeaders.Authorization = authHeader; m_http.DefaultRequestHeaders.Authorization = authHeader;
m_navigationManager.NavigateTo("/"); m_navigationManager.NavigateTo("/");
} }
else if (responseMain.StatusCode == System.Net.HttpStatusCode.BadRequest) else if (responseMain.StatusCode == System.Net.HttpStatusCode.BadRequest)
{ {
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
@ -108,5 +118,18 @@ namespace Biskilog_Accounting.Client.Pages.Auth
m_password = value; m_password = value;
StateHasChanged(); StateHasChanged();
} }
public string errormeaasge(string message)
{
showPasswordError = string.IsNullOrEmpty(m_email);
showUsernameError = string.IsNullOrEmpty(m_password);
if (showUsernameError && showPasswordError)
{
message = "";
}
return message;
}
} }
} }

10
Client/Properties/launchSettings.json

@ -8,23 +8,23 @@
"profiles": { "profiles": {
"http": { "http": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5136", "applicationUrl": "http://localhost:5136",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} },
"dotnetRunMessages": true
}, },
"https": { "https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7247;http://localhost:5136", "applicationUrl": "https://localhost:7247;http://localhost:5136",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} },
"dotnetRunMessages": true
}, },
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
@ -35,4 +35,4 @@
} }
} }
} }
} }

2
Server/Biskilog Accounting.Server.csproj

@ -8,6 +8,8 @@
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName> <AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup> <ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" /> <PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" /> <PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />

40
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": { "profiles": {
"http": { "http": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5136",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5136"
}, },
"https": { "https": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7247;http://localhost:5136",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7247;http://localhost:5136"
}, },
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "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
} }
} }
} }

3
Shared/ClientContractModels/Userauth.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Biskilog_Accounting.Shared.ClientContractModels; namespace Biskilog_Accounting.Shared.ClientContractModels;
@ -9,10 +10,12 @@ public partial class Userauth
public int ClientId { get; set; } public int ClientId { get; set; }
[Required(ErrorMessage = "Invalid username")]
public string? Username { get; set; } public string? Username { get; set; }
public string? Email { get; set; } public string? Email { get; set; }
[Required(ErrorMessage = "Invalid password")]
public string? Passsword { get; set; } public string? Passsword { get; set; }
public string? PhoneNumber { get; set; } public string? PhoneNumber { get; set; }

Loading…
Cancel
Save