añadido logging de cerrar sesion + invalidacion de token
This commit is contained in:
@@ -52,7 +52,27 @@ public class LoginController: ControllerBase
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("/api/logout")]
|
||||
public IActionResult CerrarSesion([FromHeader(Name = "Auth")]string Auth){
|
||||
var cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null ) return BadRequest(new { message = "No hay un cliente con ese token" });
|
||||
|
||||
var log = new LoginDto {
|
||||
Email = cli.Email,
|
||||
Contraseña = "",
|
||||
};
|
||||
|
||||
string tokenString = GenerarToken(log);
|
||||
|
||||
try{
|
||||
RepositorioUsuarios.Singleton.GuardarToken(log, tokenString, Request.HttpContext.Connection.RemoteIpAddress, "Cerrar Sesión");
|
||||
} catch {
|
||||
return BadRequest( new { message = "Fallo al cambiar el token" } );
|
||||
}
|
||||
return Ok(new { message = "Se Cerro la sesion" });
|
||||
}
|
||||
|
||||
private string GenerarToken(LoginDto loginDto){
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes("ffb2cdc15d472e41a5b626e294c45020");
|
||||
|
||||
Reference in New Issue
Block a user