42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
|
|
using Dapper;
|
||
|
|
using GestionIntegral.Api.Models;
|
||
|
|
using System.Data;
|
||
|
|
|
||
|
|
namespace GestionIntegral.Api.Data
|
||
|
|
{
|
||
|
|
public class AuthRepository : IAuthRepository
|
||
|
|
{
|
||
|
|
private readonly DbConnectionFactory _connectionFactory;
|
||
|
|
|
||
|
|
public AuthRepository(DbConnectionFactory connectionFactory)
|
||
|
|
{
|
||
|
|
_connectionFactory = connectionFactory;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<Usuario?> GetUserByUsernameAsync(string username)
|
||
|
|
{
|
||
|
|
var sql = @"SELECT Id, [User], ClaveHash, ClaveSalt, Habilitada,
|
||
|
|
SupAdmin, Nombre, Apellido, IdPerfil, VerLog, DebeCambiarClave
|
||
|
|
FROM gral_Usuarios
|
||
|
|
WHERE [User] = @Username";
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
using (var connection = _connectionFactory.CreateConnection())
|
||
|
|
{
|
||
|
|
var user = await connection.QuerySingleOrDefaultAsync<Usuario>(sql, new { Username = username });
|
||
|
|
return user;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
// Loggear el error ex.Message
|
||
|
|
Console.WriteLine($"Error fetching user: {ex.Message}");
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TODO: Implementar métodos para cambiar clave (UPDATE seguro con parámetros)
|
||
|
|
// y para crear usuario (INSERT seguro con parámetros, usando el hasher)
|
||
|
|
}
|
||
|
|
}
|