Browse Source

Added update to validation

BISKI2023-18
parent
commit
14643333e6
  1. 16
      Client/Pages/Auth/Login.razor
  2. 23
      Client/Pages/Auth/Login.razor.cs

16
Client/Pages/Auth/Login.razor

@ -81,19 +81,29 @@
<form>
<p>Please login to your account</p>
<Microsoft.AspNetCore.Components.Forms.DataAnnotationsValidator/>
<div class="form-outline mb-4">
<input type="email" id="form2Example11" class="form-control"
placeholder="Phone number or email address" @oninput="@(args => usernameInput(args.Value.ToString()))" @onkeydown="@Enter" />
<label class="form-label" for="form2Example11">Username</label>
<Microsoft.AspNetCore.Components.Forms.ValidationMessage For="@(() => authenticatedUser.Username)"/>
@if (showUsernameError)
{
<p class="text-danger">Enter valid Uaername</p>
}
</div>
<div class="form-outline mb-4">
<input type="password" id="form2Example22" class="form-control" @oninput="@(args => passwordInput(args.Value.ToString()))" @onkeydown="@Enter" />
<label class="form-label" for="form2Example22">Password</label>
<Microsoft.AspNetCore.Components.Forms.ValidationMessage For="@(() => authenticatedUser.Passsword)"/>
@if (showPasswordError)
{
<p class="text-danger">Enter valid Password</p>
}
</div>
<div class="text-center pt-1 mb-5 pb-1">

23
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;
/// <summary>
@ -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();
}
}
}
Loading…
Cancel
Save