Ejemplo n.º 1
0
        public ActionResult Access(Users user)
        {
            try
            {
                var  codeAccess = Request["id"];
                bool Invalid    = false;

                #region Validações
                if (user.Password == null)
                {
                    ModelState.AddModelError("Password", "O campo senha deve ser informado.");
                    Invalid = true;
                }

                if (user.PasswordRecover == null)
                {
                    ModelState.AddModelError("PasswordRecover", "O campo Repita nova senha deve ser informado.");
                    Invalid = true;
                }

                if (user.Password != user.PasswordRecover)
                {
                    ModelState.AddModelError("PasswordRecover", "O campo Repita nova senha não é igual ao campo senha.");
                    Invalid = true;
                }
                #endregion

                if (Invalid.Equals(false))
                {
                    if (user.Password.Equals(user.PasswordRecover))
                    {
                        //Recupera objeto user do password Recover
                        List <Users> listUser = uow.UserRepositorio.GetAll().Where(x => x.PasswordRecover.Equals(codeAccess)).ToList();
                        if (listUser.Count().Equals(1))
                        {
                            foreach (var item in listUser)
                            {
                                item.Password        = Md5Hash.CalculaHash(user.Password);
                                item.PasswordRecover = null;

                                //Atualiza repositório
                                uow.UserRepositorio.Atualizar(item);
                                uow.Commit();
                            }
                        }

                        return(RedirectToAction("AccessSuccess", "Default"));
                    }
                }

                return(View());
            }
            catch (Exception ex)
            {
                Common.SendLogError(0, ex);
                return(RedirectToAction("Login", "Default"));
            }
        }
Ejemplo n.º 2
0
        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());
        }