public async Task <IActionResult> EsqueciSenha(EsqueciSenhaModel model) { try { if (ModelState.IsValid) { string token; var result = await _loginService.EsqueciSenhaService(model, out token); if (result) { var urlResult = Url.Action("ResetarSenha", "LoginUsuario", new { token = token, email = model.Email }, Request.Scheme); var emailModel = new RegistraUsuarioModel { Email = model.Email, }; await Email.Enviar(emailModel, "Alterar senha - WebReceitas", urlResult); var msg = "Agora verifique seu email e siga as istrucoes enviadas"; return(RedirectToAction("Confirmacao", "LoginUsuario", new { mensagem = msg })); } ModelState.AddModelError("", "Este usuario(email) nao existe!!"); return(View()); } return(View()); } catch (Exception) { return(RedirectToAction("HttpStatusCodeHandler", "Home", new { statusCode = this.Response.StatusCode = 500 })); } }
public Task <bool> EsqueciSenhaService(EsqueciSenhaModel model, out string token) { token = string.Empty; StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = _client.PostAsync("Login/ForgotPassword", content).Result; if (response.IsSuccessStatusCode) { var apiResponse = response.Content.ReadAsStringAsync().Result; token = apiResponse; return(Task.FromResult(true)); } else if (response.StatusCode == HttpStatusCode.InternalServerError) { throw new Exception(); } return(Task.FromResult(false)); }