Cambios en el login interno y externo
This commit is contained in:
parent
b2c7b03166
commit
66eccce253
@ -41,7 +41,9 @@ namespace ApiGateway
|
|||||||
String.Equals(calledUrl, "/ldap/Conectar") ||
|
String.Equals(calledUrl, "/ldap/Conectar") ||
|
||||||
String.Equals(calledUrl, "/Ext/Login") ||
|
String.Equals(calledUrl, "/Ext/Login") ||
|
||||||
String.Equals(calledUrl, "/Auth/Login") ||
|
String.Equals(calledUrl, "/Auth/Login") ||
|
||||||
|
String.Equals(calledUrl, "/Auth/BloquearUsuario") ||
|
||||||
String.Equals(calledUrl, "/Auth/CambiarClave") ||
|
String.Equals(calledUrl, "/Auth/CambiarClave") ||
|
||||||
|
String.Equals(calledUrl, "/UsuariosTemp") ||
|
||||||
String.Equals(calledUrl, "/Auth/TknCambioClave") ||
|
String.Equals(calledUrl, "/Auth/TknCambioClave") ||
|
||||||
String.Equals(calledUrl, "/Auth/Proveedor") ||
|
String.Equals(calledUrl, "/Auth/Proveedor") ||
|
||||||
String.Equals(calledUrl, "/Email") ||
|
String.Equals(calledUrl, "/Email") ||
|
||||||
|
@ -34,5 +34,9 @@ namespace MSAdminUsuarios.Context
|
|||||||
public int? NU_TIPOUSUARIO_USUMS { get; set; }
|
public int? NU_TIPOUSUARIO_USUMS { get; set; }
|
||||||
public string? TX_REGPROF_MDC { get; set; }
|
public string? TX_REGPROF_MDC { get; set; }
|
||||||
public string? TX_MSORIGEN_USUMS { get; set; }
|
public string? TX_MSORIGEN_USUMS { get; set; }
|
||||||
|
public int? NU_INICIO_PRIMERAVEZ_USUMS { get; set; }
|
||||||
|
public DateTime? FE_INICIOACTIVACION_USUTMP { get; set; }
|
||||||
|
public DateTime? FE_FINACTIVACION_USUTMP { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,26 +70,31 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
return Ok(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
token = token,
|
token = token,
|
||||||
user = userldap.TX_PKDOC_USUMS
|
user = userldap.TX_PKDOC_USUMS,
|
||||||
|
ldap = 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
}else if(userldap.BL_VIENELDAP_USUMS != 1)
|
}else if(userldap.BL_VIENELDAP_USUMS != 1) //return BadRequest(new ResLoginExt("No eres un usuario interno.", true, userldap.NU_ESTADO_USUMS));
|
||||||
{
|
{
|
||||||
USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == login.TX_LOGINNAME_USUMS && u.TX_PASSWORD_USUMS == _encript.EncryptPwd(login.TX_PASSWORD_USUMS));
|
/*USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == login.TX_LOGINNAME_USUMS && u.TX_PASSWORD_USUMS == _encript.EncryptPwd(login.TX_PASSWORD_USUMS));
|
||||||
|
if (user == null) return BadRequest("Usuario o contraseña incorrectos");*/
|
||||||
|
|
||||||
if (user == null) return BadRequest("Usuario o contraseña incorrectos");
|
//if (userldap.BL_VIENELDAP_USUMS != 1)
|
||||||
|
return BadRequest("No eres un usuario interno");
|
||||||
|
|
||||||
string token = Token(user);
|
/*string token = Token(user);
|
||||||
|
|
||||||
return Ok(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
token = token,
|
token = token,
|
||||||
user = user.TX_PKDOC_USUMS
|
user = user.TX_PKDOC_USUMS,
|
||||||
});
|
primera = user.NU_INICIO_PRIMERAVEZ_USUMS,
|
||||||
|
ldap = 0
|
||||||
|
});*/
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
return BadRequest("Error");
|
return BadRequest("Error");
|
||||||
@ -103,7 +108,7 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("CambiarClave")]
|
/*[HttpPost("CambiarClave_old")]
|
||||||
public IActionResult CambiarClave([FromBody] USUARIO us)
|
public IActionResult CambiarClave([FromBody] USUARIO us)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -123,7 +128,7 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
{
|
{
|
||||||
return Conflict(e.Message);
|
return Conflict(e.Message);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
[HttpPost("Proveedor")]
|
[HttpPost("Proveedor")]
|
||||||
public IActionResult LoginProveedores([FromBody] LoginModel login)
|
public IActionResult LoginProveedores([FromBody] LoginModel login)
|
||||||
@ -139,14 +144,15 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
if (userExist == null) return BadRequest(new ResLoginExt("Usuario o contrase<73>a incorrectos"));
|
if (userExist == null) return BadRequest(new ResLoginExt("Usuario o contrase<73>a incorrectos"));
|
||||||
|
|
||||||
USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == login.TX_LOGINNAME_USUMS && u.TX_PASSWORD_USUMS == _encript.EncryptPwd(login.TX_PASSWORD_USUMS));
|
USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == login.TX_LOGINNAME_USUMS && u.TX_PASSWORD_USUMS == _encript.EncryptPwd(login.TX_PASSWORD_USUMS));
|
||||||
|
if (user == null) return BadRequest(new ResLoginExt("Usuario o contraseña incorrectos", true, userExist.NU_ESTADO_USUMS));
|
||||||
|
|
||||||
if (user == null) return BadRequest(new ResLoginExt("Usuario o contrase<73>a incorrectos", true, userExist.NU_ESTADO_USUMS));
|
if (user.NU_ESTADO_USUMS != 1) return BadRequest(new ResLoginExt("Usuario inactivo, bloqueado o eliminado.", true, user.NU_ESTADO_USUMS));
|
||||||
|
|
||||||
if (user.NU_ESTADO_USUMS != 1) return BadRequest(new ResLoginExt("Usuario inactivo o eliminado.", true, user.NU_ESTADO_USUMS));
|
if (user.BL_VIENELDAP_USUMS != 0) return BadRequest(new ResLoginExt("No eres un usuario externo.", true, user.NU_ESTADO_USUMS));
|
||||||
|
|
||||||
string token = Token(user);
|
string token = Token(user);
|
||||||
|
|
||||||
return Ok(new ResLoginExt("Bienvenido al sistema.", true, user.NU_ESTADO_USUMS, token));
|
return Ok(new ResLoginExt("Bienvenido al sistema.", true, user.NU_ESTADO_USUMS, token, user.NU_INICIO_PRIMERAVEZ_USUMS, user.TX_PKDOC_USUMS, user.BL_VIENELDAP_USUMS));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -319,17 +325,53 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
if (usuario == null) throw new Exception("Usuario no encontrado");
|
if (usuario == null) throw new Exception("Usuario no encontrado");
|
||||||
USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == usuario);
|
USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == usuario);
|
||||||
if (user == null) throw new Exception("Usuario no encontrado");
|
if (user == null) throw new Exception("Usuario no encontrado");
|
||||||
user.NU_BLOQUEO_USUMS = 0;
|
//user.NU_BLOQUEO_USUMS = 0;
|
||||||
user.NU_ESTADO_USUMS = 2;
|
user.NU_ESTADO_USUMS = 2;
|
||||||
|
|
||||||
_context.USUARIOSMs.Update(user);
|
_context.USUARIOSMs.Update(user);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
return Ok(new { message = "Su cuenta ha sido bloqueada debido a demasiados intentos fallidos" });
|
//return Ok(new { message = "Su cuenta ha sido bloqueada debido a demasiados intentos fallidos" });
|
||||||
|
//return Ok("Su cuenta ha sido bloqueada debido a demasiados intentos fallidos");
|
||||||
|
return Ok(new ResLoginExt("Su cuenta ha sido bloqueada debido a demasiados intentos fallidos.", true));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { message = ex.Message });
|
//return BadRequest(new { message = ex.Message });
|
||||||
|
//return BadRequest(ex.Message);
|
||||||
|
return BadRequest(new ResLoginExt(ex.Message, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("CambiarClave")]
|
||||||
|
public IActionResult CambiarClave([FromBody] CambiarClaveModel model)
|
||||||
|
{
|
||||||
|
if (model.NewPassword != model.ConfirmPassword)
|
||||||
|
{
|
||||||
|
return BadRequest("Las contraseñas no coinciden.");
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (model == null) throw new Exception("No se recibieron datos");
|
||||||
|
USUARIO? user = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == model.User);
|
||||||
|
if (user == null) return BadRequest("Usuario no encontrado.");
|
||||||
|
|
||||||
|
string newPass = _encript.EncryptPwd(model.NewPassword!);
|
||||||
|
user.TX_PASSWORD_USUMS = newPass;
|
||||||
|
user.NU_INICIO_PRIMERAVEZ_USUMS = 1;
|
||||||
|
|
||||||
|
_context.USUARIOSMs.Update(user);
|
||||||
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
//return Ok("Contrase<73>a restablecida con éxito.");
|
||||||
|
//return Ok(new { message = "Contrase<73>a restablecida con éxito." });
|
||||||
|
return Ok(new ResLoginExt("Contrase<73>a restablecida con éxito.", true));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//return Conflict(e.Message);
|
||||||
|
//return BadRequest(new { message = ex.Message });
|
||||||
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,18 +420,31 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
public class ResLoginExt
|
public class ResLoginExt
|
||||||
{
|
{
|
||||||
|
|
||||||
public ResLoginExt(string _message, bool _exist = false, int? _estado = null, string? _token = "")
|
public ResLoginExt(string _message, bool _exist = false, int? _estado = null, string? _token = "", int? _primera = null, string? _user = "", int? _ldap = null)
|
||||||
{
|
{
|
||||||
Message = _message;
|
Message = _message;
|
||||||
Token = _token;
|
Token = _token;
|
||||||
Existe = _exist;
|
Existe = _exist;
|
||||||
Estado = _estado;
|
Estado = _estado;
|
||||||
|
Primera = _primera;
|
||||||
|
User = _user;
|
||||||
|
Ldap = _ldap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Existe { get; set; }
|
public bool Existe { get; set; }
|
||||||
public int? Estado { get; set; }
|
public int? Estado { get; set; }
|
||||||
public string? Token { get; set; }
|
public string? Token { get; set; }
|
||||||
public string Message { get; set; } = null!;
|
public string Message { get; set; } = null!;
|
||||||
|
public int? Primera { get; set; }
|
||||||
|
public string? User { get; set; }
|
||||||
|
public int? Ldap { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CambiarClaveModel
|
||||||
|
{
|
||||||
|
public string User { get; set; }
|
||||||
|
public string NewPassword { get; set; }
|
||||||
|
public string ConfirmPassword { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Options
|
static class Options
|
||||||
|
@ -22,7 +22,7 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
{
|
{
|
||||||
/*var consulta = from dm in _context.MICROSERVICIOs
|
/*var consulta = from dm in _context.MICROSERVICIOs
|
||||||
select dm;*/
|
select dm;*/
|
||||||
List<MICROSERVICIO> microservicios = await _context.MICROSERVICIOs.OrderBy(m => m.NU_PK_MS).ToListAsync();
|
List<MICROSERVICIO> microservicios = await _context.MICROSERVICIOs.OrderBy(m => m.TX_SECCION_MS).ToListAsync();
|
||||||
return Ok(microservicios);
|
return Ok(microservicios);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -284,6 +284,8 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
existe.NU_BLOQUEO_USUMS = editado.NU_BLOQUEO_USUMS;
|
existe.NU_BLOQUEO_USUMS = editado.NU_BLOQUEO_USUMS;
|
||||||
existe.NU_TIPOUSUARIO_USUMS = editado.NU_TIPOUSUARIO_USUMS;
|
existe.NU_TIPOUSUARIO_USUMS = editado.NU_TIPOUSUARIO_USUMS;
|
||||||
existe.TX_REGPROF_MDC = editado.TX_REGPROF_MDC;
|
existe.TX_REGPROF_MDC = editado.TX_REGPROF_MDC;
|
||||||
|
existe.FE_INICIOACTIVACION_USUTMP = editado.FE_INICIOACTIVACION_USUTMP;
|
||||||
|
existe.FE_FINACTIVACION_USUTMP = editado.FE_FINACTIVACION_USUTMP;
|
||||||
|
|
||||||
ErrorModel errorPFLxUSUMS = await ActualizarRelaciones(existe.TX_PKDOC_USUMS, editado.TX_PKDOC_USUMS);
|
ErrorModel errorPFLxUSUMS = await ActualizarRelaciones(existe.TX_PKDOC_USUMS, editado.TX_PKDOC_USUMS);
|
||||||
|
|
||||||
@ -592,6 +594,8 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
nuevo.usuario.TX_SEDES_USUMS = "[0]";
|
nuevo.usuario.TX_SEDES_USUMS = "[0]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nuevo.usuario.NU_INICIO_PRIMERAVEZ_USUMS = 0;
|
||||||
|
|
||||||
_context.USUARIOSMs.Add(nuevo.usuario);
|
_context.USUARIOSMs.Add(nuevo.usuario);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
@ -625,6 +629,8 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
existe.NU_BLOQUEO_USUMS = nuevo.usuario.NU_BLOQUEO_USUMS;
|
existe.NU_BLOQUEO_USUMS = nuevo.usuario.NU_BLOQUEO_USUMS;
|
||||||
existe.NU_TIPOUSUARIO_USUMS = nuevo.usuario.NU_TIPOUSUARIO_USUMS;
|
existe.NU_TIPOUSUARIO_USUMS = nuevo.usuario.NU_TIPOUSUARIO_USUMS;
|
||||||
existe.TX_REGPROF_MDC = nuevo.usuario.TX_REGPROF_MDC;
|
existe.TX_REGPROF_MDC = nuevo.usuario.TX_REGPROF_MDC;
|
||||||
|
existe.FE_INICIOACTIVACION_USUTMP = nuevo.usuario.FE_INICIOACTIVACION_USUTMP;
|
||||||
|
existe.FE_FINACTIVACION_USUTMP = nuevo.usuario.FE_FINACTIVACION_USUTMP;
|
||||||
|
|
||||||
if (existe.TX_PASSWORD_USUMS == null || existe.TX_PASSWORD_USUMS == "")
|
if (existe.TX_PASSWORD_USUMS == null || existe.TX_PASSWORD_USUMS == "")
|
||||||
{
|
{
|
||||||
@ -789,6 +795,8 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
existe.NU_BLOQUEO_USUMS = nuevo.usuario.NU_BLOQUEO_USUMS;
|
existe.NU_BLOQUEO_USUMS = nuevo.usuario.NU_BLOQUEO_USUMS;
|
||||||
existe.NU_TIPOUSUARIO_USUMS = nuevo.usuario.NU_TIPOUSUARIO_USUMS;
|
existe.NU_TIPOUSUARIO_USUMS = nuevo.usuario.NU_TIPOUSUARIO_USUMS;
|
||||||
existe.TX_REGPROF_MDC = nuevo.usuario.TX_REGPROF_MDC;
|
existe.TX_REGPROF_MDC = nuevo.usuario.TX_REGPROF_MDC;
|
||||||
|
existe.FE_INICIOACTIVACION_USUTMP = nuevo.usuario.FE_INICIOACTIVACION_USUTMP;
|
||||||
|
existe.FE_FINACTIVACION_USUTMP = nuevo.usuario.FE_FINACTIVACION_USUTMP;
|
||||||
|
|
||||||
if (existe.TX_PASSWORD_USUMS == null || existe.TX_PASSWORD_USUMS == "")
|
if (existe.TX_PASSWORD_USUMS == null || existe.TX_PASSWORD_USUMS == "")
|
||||||
{
|
{
|
||||||
|
@ -41,5 +41,7 @@ namespace MSAdminUsuarios.Dto
|
|||||||
public string? TX_UUID_USUMS { get; set; }
|
public string? TX_UUID_USUMS { get; set; }
|
||||||
public int? NU_TIPOUSUARIO_USUMS { get; set; }
|
public int? NU_TIPOUSUARIO_USUMS { get; set; }
|
||||||
public string? TX_REGPROF_MDC { get; set; }
|
public string? TX_REGPROF_MDC { get; set; }
|
||||||
|
public DateTime? FE_INICIOACTIVACION_USUTMP { get; set; }
|
||||||
|
public DateTime? FE_FINACTIVACION_USUTMP { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user