implementado login a travez de coockies
This commit is contained in:
@@ -21,17 +21,29 @@ public class LoginController: ControllerBase
|
||||
string tokenString = GenerarToken(loginDto);
|
||||
RepositorioUsuarios.Singleton.GuardarToken(loginDto, tokenString);
|
||||
|
||||
return Ok( new {Email = loginDto.Email, Token = tokenString, Redirect = "/Menu"});
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
//SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTimeOffset.UtcNow.AddHours(1)
|
||||
};
|
||||
|
||||
Response.Cookies.Append("token", tokenString, cookieOptions);
|
||||
return Ok( new {Email = loginDto.Email, 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)
|
||||
public IActionResult Verificar([FromBody] AccessDto request){
|
||||
|
||||
Request.Cookies.TryGetValue("token", out var token);
|
||||
|
||||
if (request.Email == String.Empty || token == null ||request.Redirect == string.Empty)
|
||||
{
|
||||
return Unauthorized(new { esValido = false});
|
||||
}
|
||||
|
||||
bool esValido = RepositorioUsuarios.Singleton.CheckToken(tokenRequest);
|
||||
bool esValido = RepositorioUsuarios.Singleton.CheckToken(request.Email, token);
|
||||
return (esValido) ?
|
||||
Ok( new { esValido = true}) : Unauthorized( new {esValido = false});
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ builder.Services.AddCors(options =>
|
||||
options.AddPolicy("AllowSvelteApp",
|
||||
builder =>
|
||||
{
|
||||
builder.AllowAnyOrigin()
|
||||
builder.WithOrigins("http://localhost:5173")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user