reestructuracion de las entidades
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
@@ -16,13 +16,27 @@ public class LoginController: ControllerBase
|
||||
if (loginDto.Email == String.Empty || loginDto.Contraseña == String.Empty) return Unauthorized(new {message = "Los Datos no llegaron correctamente o faltan"});
|
||||
|
||||
var usuario = RepositorioUsuarios.Singleton.CheckUsuario(loginDto);
|
||||
if (usuario == null) 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);
|
||||
return Ok( new {Token = tokenString, Redirect = "/Menu"});
|
||||
RepositorioUsuarios.Singleton.GuardarToken(loginDto, tokenString);
|
||||
|
||||
return Ok( new {Email = loginDto.Email, Token = tokenString, Redirect = "/Menu"});
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("api/login/validar")]
|
||||
public IActionResult Verificar([FromBody] TokenDto tokenRequest){
|
||||
if (tokenRequest.Email == String.Empty ||tokenRequest.Token == string.Empty ||tokenRequest.Redirect == string.Empty)
|
||||
{
|
||||
return Unauthorized(new { esValido = false});
|
||||
}
|
||||
|
||||
bool esValido = RepositorioUsuarios.Singleton.CheckToken(tokenRequest);
|
||||
return (esValido) ?
|
||||
Ok( new { esValido = true}) : Unauthorized( new {esValido = false});
|
||||
}
|
||||
|
||||
|
||||
private string GenerarToken(LoginDto loginDto){
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes("ffb2cdc15d472e41a5b626e294c45020");
|
||||
|
||||
Reference in New Issue
Block a user