Fase 1: Inicialización del Backend .NET 10, Configuración de Dapper, Autenticación JWT y Entidades Base
This commit is contained in:
27
src/SIGCM.Infrastructure/Services/AuthService.cs
Normal file
27
src/SIGCM.Infrastructure/Services/AuthService.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using SIGCM.Application.Interfaces;
|
||||
using SIGCM.Domain.Interfaces;
|
||||
|
||||
namespace SIGCM.Infrastructure.Services;
|
||||
|
||||
public class AuthService : IAuthService
|
||||
{
|
||||
private readonly IUserRepository _userRepo;
|
||||
private readonly ITokenService _tokenService;
|
||||
|
||||
public AuthService(IUserRepository userRepo, ITokenService tokenService)
|
||||
{
|
||||
_userRepo = userRepo;
|
||||
_tokenService = tokenService;
|
||||
}
|
||||
|
||||
public async Task<string?> LoginAsync(string username, string password)
|
||||
{
|
||||
var user = await _userRepo.GetByUsernameAsync(username);
|
||||
if (user == null) return null;
|
||||
|
||||
bool valid = BCrypt.Net.BCrypt.Verify(password, user.PasswordHash);
|
||||
if (!valid) return null;
|
||||
|
||||
return _tokenService.GenerateToken(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user