Browse Source

Added latest validation update

BISKI2023-18
parent
commit
489d1f46c0
  1. 14
      Client/Pages/Auth/Login.razor
  2. 36
      Client/Pages/Auth/Login.razor.cs

14
Client/Pages/Auth/Login.razor

@ -87,21 +87,19 @@
<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 (showUsernameError)
{
<p class="text-danger">Enter valid Uaername</p>
} @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 (showPasswordError) @if (!validStatus)
{ {
<p class="text-danger">Enter valid Password</p> <p class="text-danger">@errormeaasge("invalid")</p>
} }
</div> </div>

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

@ -13,6 +13,7 @@ namespace Biskilog_Accounting.Client.Pages.Auth
private bool showUsernameError, showPasswordError; private bool showUsernameError, showPasswordError;
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;
//NotificationMessage notificationMessage = new NotificationMessage(); //NotificationMessage notificationMessage = new NotificationMessage();
private Userauth authenticatedUser; private Userauth authenticatedUser;
@ -47,28 +48,26 @@ 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)
{ {
showUsernameError = string.IsNullOrEmpty(m_email);
showPasswordError = string.IsNullOrEmpty(m_password);
if(!showUsernameError && !showPasswordError) validStatus = true;
{
string token = await responseMain.Content.ReadAsStringAsync();
await m_tokenService.SetToken(token, m_remember);
var authHeader = new AuthenticationHeaderValue("Bearer", token); string token = await responseMain.Content.ReadAsStringAsync();
m_http.DefaultRequestHeaders.Authorization = authHeader; 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) else if (responseMain.StatusCode == System.Net.HttpStatusCode.BadRequest)
{ {
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
@ -120,6 +119,17 @@ namespace Biskilog_Accounting.Client.Pages.Auth
StateHasChanged(); StateHasChanged();
} }
public string errormeaasge(string message)
{
showPasswordError = string.IsNullOrEmpty(m_email);
showUsernameError = string.IsNullOrEmpty(m_password);
if (showUsernameError && showPasswordError)
{
message = "";
}
return message;
}
} }
} }
Loading…
Cancel
Save