new init api and start auth

This commit is contained in:
Riccardo Usardi committed 2025-07-06 21:37:41 +02:00
1 parent 7941a858fd
commit a172f05269
26 files changed
+640 -102

No files matched your search

@@ -0,0 +1,40 @@
using Microsoft.Extensions.Configuration;
using MySqlConnector;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uWine.Core.Domain.Entities;
using uWine.Core.Domain.Repositories;
namespace uWine.Core.Infrastructure.Repository
{
public class MariaDbAuthenticationRepository : MariaDbServerRepository, IAuthenticationRepository
{
public MariaDbAuthenticationRepository(IConfiguration configuration) : base(configuration)
{
}
public bool Valid(User user)
{
if (user == null || string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password)) return false;
using (var conn = Connection())
{
var cmd = new MySqlCommand("sp_check_login", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", user.Username);
cmd.Parameters.AddWithValue("@Password", user.Password);
using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
return reader.GetBoolean("valid");
}
}
}
return false;
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uWine.Core.Domain.Entities;
using uWine.Core.Domain.Repositories;
namespace uWine.Core.Infrastructure.Services
{
public class AuthenticationService
{
readonly IAuthenticationRepository _authenticationRepository;
public AuthenticationService(IAuthenticationRepository authenticationRepository)
{
_authenticationRepository = authenticationRepository;
}
public bool IsAuthenticated(User user)
{
return _authenticationRepository.Valid(user);
}
}
}
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uWine.Core.Domain.Entities;
using uWine.Core.Domain.Repositories;
namespace uWine.Core.Infrastructure.Services
{
public class OwnerService
{
IOwnerRepository _ownerRepository;
IAddressRepository _addressRepository;
IContactRepository _contactRepository;
IVineyardRepository _vineyardRepository;
public OwnerService(
IOwnerRepository ownerRepository,
IAddressRepository addressRepository,
IContactRepository contactRepository,
IVineyardRepository vineyardRepository
)
{
_ownerRepository = ownerRepository;
_addressRepository = addressRepository;
_contactRepository = contactRepository;
_vineyardRepository = vineyardRepository;
}
public Owner FillData(Owner owner)
{
owner.Addresses =_addressRepository.OwnerAddresses(owner.Id);
owner.Contacts = _contactRepository.OwnerContacts(owner.Id);
owner.Vineyards = _vineyardRepository.GetOwnerVineyards(owner.Id);
return owner;
}
}
}