Fase 2: Creatción de la UI (React + Vite). Implementación de Log In reemplazando texto plano. Y creación de tool para migrar contraseñas.
This commit is contained in:
42
Backend/GestionIntegral.Api/Data/AuthRepository.cs
Normal file
42
Backend/GestionIntegral.Api/Data/AuthRepository.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
10
Backend/GestionIntegral.Api/Data/IAuthRepository.cs
Normal file
10
Backend/GestionIntegral.Api/Data/IAuthRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using GestionIntegral.Api.Models;
|
||||
|
||||
namespace GestionIntegral.Api.Data
|
||||
{
|
||||
public interface IAuthRepository
|
||||
{
|
||||
Task<Usuario?> GetUserByUsernameAsync(string username);
|
||||
// Añadiremos métodos para cambiar clave, etc., más adelante
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user