public IActionResult Embaixador(Leega.Dtos.Pessoa model) { if (!ModelState.IsValid) { return(View(model)); } StringContent content = new StringContent(JsonSerializer.Serialize(model, typeof(Leega.Dtos.Pessoa)), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponse = apiClient.PostAsync("/pessoa/create", content).Result; if (httpResponse.IsSuccessStatusCode) { return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> Login(Models.Login model) { if (!ModelState.IsValid) { return(View(model)); } try { StringContent content = new StringContent(JsonSerializer.Serialize(model, typeof(Models.Login)), Encoding.UTF8, "application/json"); //HttpResponseMessage httpResponse = await apiClient.PostAsync("/api/Token", content); HttpResponseMessage httpResponse = await apiClient.PostAsync("/api/Token", content); var result = await httpResponse.Content.ReadAsStringAsync(); JObject Usuario = JObject.Parse(result.ToString()); if (httpResponse.IsSuccessStatusCode) { JwtSecurityToken jwtSecurityToken = new JwtSecurityTokenHandler().ReadJwtToken(Usuario["token"].ToString()); ClaimsIdentity identity = new ClaimsIdentity(jwtSecurityToken.Claims, CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaim(new Claim("token", Usuario["token"].ToString())); //identity.AddClaim(new Claim("IdOrganizacao", Usuario["IdOrganizacao"].ToString())); ClaimsPrincipal principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties() { }); var IdPessoa = new Guid(Usuario["id"].ToString()); Leega.Dtos.Pessoa pessoa = ObterLoginPessoa(IdPessoa); if (pessoa != null) { HttpContext.Session.SetString("username", pessoa.nomesocial ?? pessoa.nome); if (pessoa.imagem != null) { HttpContext.Session.SetString("userpicture", pessoa.imagem); } } else { HttpContext.Session.SetString("username", model.Usuario); } if (!string.IsNullOrEmpty(model.returnUrl)) { return(Redirect(model.returnUrl)); } return(RedirectToAction("paciente", "cadastro")); } else { if (httpResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized) { ModelState.AddModelError("password", "Login/senha incorreto"); return(View(model)); } } } catch (Exception ex) { var a = ex.Message; } return(View()); }