Browse Source

Added Login authentication

dev2
parent
commit
62fa6c626c
  1. 17
      Client/Pages/Auth/Login.razor
  2. 27
      Client/Pages/Auth/Login.razor.cs
  3. 5
      Server/Services/AuthenticationService.cs
  4. 6
      Shared/ClientContractModels/Userauth.cs

17
Client/Pages/Auth/Login.razor

@ -1,5 +1,8 @@
@layout AuthLayout
@page "/"
@inject HttpClient httpclient
@inject NavigationManager navigationmanager
<style>
.gradient-custom-2 {
/* fallback for old browsers */
@ -58,6 +61,9 @@
}
</style>
<section class="h-100 gradient-form" style="background-color: #eee;">
<div class="container py-5 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
@ -75,20 +81,25 @@
<form>
<p>Please login to your account</p>
@if (!string.IsNullOrEmpty(errormessage))
{
<p class="text-danger">@errormessage</p>
}
<div class="form-outline mb-4">
<input type="email" id="form2Example11" class="form-control"
placeholder="Phone number or email address" />
placeholder="Phone number or email address" @bind-value="@m_userAuth.Username" />
<label class="form-label" for="form2Example11">Username</label>
</div>
<div class="form-outline mb-4">
<input type="password" id="form2Example22" class="form-control" />
<input type="password" id="form2Example22" class="form-control"
@bind-value="@m_userAuth.Passsword" />
<label class="form-label" for="form2Example22">Password</label>
</div>
<div class="text-center pt-1 mb-5 pb-1">
<button class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" type="submit">
<button class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" @onclick="AuthUser" type="button">
Log
in
</button>

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

@ -1,7 +1,32 @@
namespace Biskilog_Accounting.Client.Pages.Auth
using System.Net.Http.Json;
using Biskilog_Accounting.Shared.ClientContractModels;
namespace Biskilog_Accounting.Client.Pages.Auth
{
public partial class Login
{
private Userauth m_userAuth;
private string errormessage;
protected override void OnInitialized()
{
m_userAuth = new();
base.OnInitialized();
}
public async Task AuthUser()
{
var response = await httpclient.PostAsJsonAsync("api/authentication", m_userAuth);
if (response.IsSuccessStatusCode)
{
navigationmanager.NavigateTo("/welcome");
}
else
{
errormessage = "Invalid Username or password";
}
}
}
}

5
Server/Services/AuthenticationService.cs

@ -7,10 +7,11 @@ namespace Biskilog_Accounting.Server.Services
{
public class AuthenticationService : IAuthService
{
private readonly BiskilogContext m_context;
private readonly ITokenService m_tokenService;
public AuthenticationService(BiskilogContext a_context, ITokenService a_tokenService)
public AuthenticationService( BiskilogContext a_context, ITokenService a_tokenService)
{
m_context = a_context;
m_tokenService = a_tokenService;
@ -124,8 +125,10 @@ namespace Biskilog_Accounting.Server.Services
// if (verified)
// {
//TODO have a complete implementation
return await m_context.Userauths.FirstAsync(u => u.Username == username && u.Passsword == password);
// }
// else
// {

6
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,15 @@ public partial class Userauth
public int ClientId { get; set; }
[Required]
[Display(Name = "Username")]
public string? Username { get; set; }
public string? Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string? Passsword { get; set; }
public string? PhoneNumber { get; set; }

Loading…
Cancel
Save