añadido que logee la ip y los logins
This commit is contained in:
@@ -19,7 +19,7 @@ public class LoginController: ControllerBase
|
|||||||
if (!usuario) return Unauthorized(new {message = "El usuario no existe o la contraseña es incorrecta"});
|
if (!usuario) return Unauthorized(new {message = "El usuario no existe o la contraseña es incorrecta"});
|
||||||
|
|
||||||
string tokenString = GenerarToken(loginDto);
|
string tokenString = GenerarToken(loginDto);
|
||||||
RepositorioUsuarios.Singleton.GuardarToken(loginDto, tokenString);
|
RepositorioUsuarios.Singleton.GuardarToken(loginDto, tokenString, Request.HttpContext.Connection.RemoteIpAddress);
|
||||||
|
|
||||||
var cookieOptions = new CookieOptions
|
var cookieOptions = new CookieOptions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Net;
|
||||||
using Entidades;
|
using Entidades;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@@ -28,6 +29,31 @@ public class AuditoriaFacade {
|
|||||||
_persistenciaDeLog.GuardarLog(log, log.LogDetalles);
|
_persistenciaDeLog.GuardarLog(log, log.LogDetalles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void GenerarLogLogin(long dni, string v, IPAddress? remoteIpAddress) {
|
||||||
|
var fechaActual = DateTime.Now;
|
||||||
|
|
||||||
|
var log = new Log{
|
||||||
|
Fecha = fechaActual,
|
||||||
|
Dniusuario = dni,
|
||||||
|
Accion = v
|
||||||
|
};
|
||||||
|
|
||||||
|
log.LogDetalles = new List<LogDetalle>([
|
||||||
|
new LogDetalle{
|
||||||
|
Id = 1,
|
||||||
|
Dniusuario = dni,
|
||||||
|
Fecha = fechaActual,
|
||||||
|
NombreTabla = "Logs",
|
||||||
|
Columna = "Login",
|
||||||
|
ValorAnterior = "",
|
||||||
|
ValorNuevo = $"Se inicio sesión con la direccion ip: {remoteIpAddress.ToString()}",
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
_persistenciaDeLog.GuardarLog(log, log.LogDetalles);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private List<LogDetalle> ProcesarCambios(IEnumerable<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> cambios,
|
private List<LogDetalle> ProcesarCambios(IEnumerable<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> cambios,
|
||||||
DateTime fechaActual, long dniUsuario) {
|
DateTime fechaActual, long dniUsuario) {
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using Entidades.Dto;
|
|||||||
using Entidades;
|
using Entidades;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Entidades.Admin;
|
using Entidades.Admin;
|
||||||
|
using System.Net;
|
||||||
|
using Modelo.Facade;
|
||||||
|
|
||||||
namespace Modelo;
|
namespace Modelo;
|
||||||
|
|
||||||
@@ -95,14 +97,22 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
|||||||
return usu.Token == token;
|
return usu.Token == token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GuardarToken(LoginDto login, string tokenString) {
|
public void GuardarToken(LoginDto login, string tokenString, System.Net.IPAddress? remoteIpAddress) {
|
||||||
var con = Context;
|
var con = Context;
|
||||||
var usu = con.Clientes.FirstOrDefault(x => x.Email == login.Email);
|
var usu = con.Clientes.FirstOrDefault(x => x.Email == login.Email);
|
||||||
if (usu == null) return;
|
if (usu == null) return;
|
||||||
usu.Token = tokenString;
|
usu.Token = tokenString;
|
||||||
|
GenerarLog(con, usu.Dni, "Login", remoteIpAddress);
|
||||||
Guardar(con);
|
Guardar(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GenerarLog(AlquilaFacilContext con, long dni, string v, IPAddress? remoteIpAddress)
|
||||||
|
{
|
||||||
|
var Auditoria = new AuditoriaFacade(con);
|
||||||
|
Auditoria.GenerarLogLogin(dni, v, remoteIpAddress);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public bool CheckGrupo(string email, string grupo) {
|
public bool CheckGrupo(string email, string grupo) {
|
||||||
var con = Context;
|
var con = Context;
|
||||||
var usu = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Email == email);
|
var usu = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Email == email);
|
||||||
|
|||||||
Reference in New Issue
Block a user