Ajustes de creacion de usuario y log de login
This commit is contained in:
parent
ab8282bd02
commit
80679eaf57
@ -1,5 +1,6 @@
|
||||
using LdapLoginLib.Data;
|
||||
using LdapLoginLib.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.DirectoryServices.Protocols;
|
||||
|
||||
namespace LdapLoginLib
|
||||
@ -7,11 +8,13 @@ namespace LdapLoginLib
|
||||
public class LDAP
|
||||
{
|
||||
private static readonly LdapConfig _ldap = new();
|
||||
private readonly ILogger<LDAP> _logger;
|
||||
|
||||
//public LDAP()
|
||||
//{
|
||||
// _ldap = new LdapConfig();
|
||||
//}
|
||||
public LDAP(ILogger<LDAP> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
//_ldap = new LdapConfig();
|
||||
}
|
||||
|
||||
public bool Login(string password, string? document = null, string? username = null, string? email = null)
|
||||
{
|
||||
@ -25,6 +28,8 @@ namespace LdapLoginLib
|
||||
username: username,
|
||||
email: email);
|
||||
|
||||
_logger.LogInformation("Ingreso: " + userInfo.NumeroDocumento + " - " + userInfo.Usuario + " - " + userInfo.Correo);
|
||||
|
||||
//Si el usuario está inactivo...
|
||||
if (userInfo.Activo == false) return false;
|
||||
|
||||
@ -42,6 +47,7 @@ namespace LdapLoginLib
|
||||
catch (LdapException ldapEx)
|
||||
{
|
||||
//Console.WriteLine($"Authentication failed: {ldapEx.Message}");
|
||||
_logger.LogError(ldapEx.ErrorCode + " // " + ldapEx.Message);
|
||||
throw new Exception(_getErrorMessage(ldapEx.ErrorCode, ldapEx.Message));
|
||||
}
|
||||
catch
|
||||
|
@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
|
||||
<PackageReference Include="RawScape.Nini" Version="1.0.0" />
|
||||
<PackageReference Include="System.DirectoryServices.Protocols" Version="6.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||
|
@ -17,11 +17,19 @@ namespace MSAdminUsuarios.Controllers
|
||||
{
|
||||
private readonly ModelContext _context;
|
||||
private readonly Encripter _encript = new();
|
||||
private readonly LDAP _ldap = new();
|
||||
private readonly LDAP _ldap;
|
||||
|
||||
public AuthController(ModelContext context)
|
||||
{
|
||||
_context = context;
|
||||
var loggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddConsole();
|
||||
});
|
||||
|
||||
var logger = loggerFactory.CreateLogger<LDAP>();
|
||||
|
||||
_ldap = new LDAP(logger);
|
||||
}
|
||||
|
||||
[HttpPost("Login")]
|
||||
@ -29,7 +37,7 @@ namespace MSAdminUsuarios.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_encript.IsValid) return BadRequest("Lectura inv<EFBFBD>lida");
|
||||
if (!_encript.IsValid) return BadRequest("Lectura inválida");
|
||||
|
||||
if (login.TX_LOGINNAME_USUMS == null) return BadRequest("Es necesario ingresar un usuario");
|
||||
|
||||
|
@ -634,36 +634,8 @@ namespace MSAdminUsuarios.Controllers
|
||||
|
||||
_context.USUARIOSMs.Update(existe);
|
||||
_context.SaveChanges();
|
||||
|
||||
/*
|
||||
"perfiles": [
|
||||
{
|
||||
"nU_PK_PFLXUSU": 0,
|
||||
"nU_FK_PFL": 81,
|
||||
"bL_ESTADO_PFLXUSU": 1,
|
||||
"tX_UUID_PFL": "78428e6f-1eeb-4b1c-a3c7-b95a9350d568"
|
||||
}
|
||||
]
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*if (existe_login > 0)
|
||||
{
|
||||
_errorModel.error = true;
|
||||
_errorModel.cuerpo.Add($"El login \"{nuevo.usuario.TX_LOGINNAME_USUMS}\" ya está en uso");
|
||||
return Conflict(_errorModel);
|
||||
}*/
|
||||
|
||||
/*if (nuevo.usuario.TX_PKDOC_USUMS == null)
|
||||
{
|
||||
var ult = _context.USUARIOSMs.Max(x => x.NU_PK_USUMS) + 1;
|
||||
nuevo.usuario.TX_PKDOC_USUMS = ult.ToString();
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
// TODO: Validacion agregada mientras se aclara el proceso
|
||||
|
||||
USUARIO? creado = await _context.USUARIOSMs.FirstOrDefaultAsync(us => us.TX_UUID_USUMS == nuevo.usuario.TX_UUID_USUMS);
|
||||
@ -678,9 +650,9 @@ namespace MSAdminUsuarios.Controllers
|
||||
foreach (var cu in existe_plfxusu)
|
||||
{
|
||||
cu.BL_ESTADO_PFLXUSU = 0;
|
||||
_context.PERFILESPORUSUARIOs.Update(cu);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
_context.PERFILESPORUSUARIOs.UpdateRange(existe_plfxusu);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
foreach (var pxu in nuevo.perfiles)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user