public ActionResult Recover(Users user) { if (user.Email != null && user.Email != "") { //1º Validar se email existe var itens = uow.UserRepositorio.GetAll().Where(x => x.Email.Equals(user.Email) && x.Active.Equals(1)).ToList(); if (itens.Count().Equals(1)) { //2º Gerar código hash de acesso para formulário de redefinição de senha string passwordRecover = Md5Hash.CalculaHash(Md5Hash.stringRandom(8)); //3º Salvar passwordHash no cadastro do usuário foreach (var item in itens) { item.PasswordRecover = passwordRecover; uow.UserRepositorio.Atualizar(item); uow.Commit(); } //4º Preparação de email para recuperação de senha. string subject = "CRM (Teste stefanini) - Novo acesso."; //Criando html para o corpo do email //----------------------------------------- string bodyEmail = string.Empty; bodyEmail += bodyEmail = "<html>"; bodyEmail += bodyEmail = "<head>"; bodyEmail += bodyEmail = "<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>"; bodyEmail += bodyEmail = "<STYLE type='text/css'>"; bodyEmail += bodyEmail = "a:link {text-decoration: none;color: #000099}"; bodyEmail += bodyEmail = "a:active { text - decoration: none; }"; bodyEmail += bodyEmail = "a:visited { text - decoration: none; color: #000099}"; bodyEmail += bodyEmail = "a:visited {text-decoration: none;color: #000099}"; bodyEmail += bodyEmail = "a:hover { text - decoration: underline; color: #000099}"; bodyEmail += bodyEmail = "BODY{font-family:arial;}"; bodyEmail += bodyEmail = "</STYLE>"; bodyEmail += bodyEmail = "</head>"; bodyEmail += bodyEmail = "<body>"; bodyEmail += bodyEmail = "Soccer Play<br><br>"; bodyEmail += bodyEmail = "Você solicitou a recuperação de seu acesso.<br>"; bodyEmail += bodyEmail = "Para continuar clique no link abaixo e defina sua nova senha:<br>"; bodyEmail += bodyEmail = "<br><a href='http://localhost:51858/Default/Access/?id=" + passwordRecover + "' target='_blank'>Clique aqui para redefinir sua senha.</a>"; bodyEmail += bodyEmail = "</body></html>"; //Enviando email EmailService.SendEmail(user.Email, bodyEmail, subject); return(RedirectToAction("FeedBack", "Default")); } else { ModelState.AddModelError("Email", "O Email informado não foi encontrado."); } } return(View()); }