public AuthRetorno ValidaLoginUsuario(LoginRequisitor requisitor) { AuthRetorno retorno = new AuthRetorno(); AutenticacaoResponse response = repository.ValidaLoginUsuario(requisitor); retorno.authenticated = response.Autenticado; if (response.Autenticado) { ClaimsIdentity identity = new ClaimsIdentity( new GenericIdentity(requisitor.usuario, "Login"), new[] { new Claim("CookieContainer", JsonConvert.SerializeObject(response.CookieContainer), ClaimValueTypes.String, "") } ); retorno.Claims = identity; retorno.message = "OK"; } else { retorno.message = "Usuário e/ou senha não encontrados."; } return(retorno); }
public async Task <IActionResult> Index(Entities.Models.Login model) { if (ModelState.IsValid) { AuthRetorno retorno = client.ValidaLoginUsuario(new LoginRequisitor(model.Usuario, model.Senha)); if (retorno.Authenticated) { await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(retorno.Claims), new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(10) }); return(RedirectToAction(nameof(ProjetoController.Index), "Projeto")); } else { ModelState.AddModelError("usuario", retorno.Message); } } return(View(model)); }
public AuthRetorno ValidaLoginUsuario(LoginRequisitor requisitor) { AuthRetorno retorno = new AuthRetorno(); retorno.Authenticated = repository.ValidaLoginUsuario(requisitor); if (retorno.Authenticated) { ClaimsIdentity identity = new ClaimsIdentity( new GenericIdentity(requisitor.usuario, "Login")); retorno.Claims = identity; retorno.Message = "OK"; } else { retorno.Message = "Usuário e/ou senha não encontrados."; } return(retorno); }