예제 #1
0
        public IComandResult EsqueceuSenha([FromBody] EsqueceuSenhaComand command)
        {
            var result = (ComandResult)_usuarioHandler.Handle(command);

            this.Commit(result.Success);


            return(result);
        }
예제 #2
0
        public IComandResult Handle(EsqueceuSenhaComand comand)
        {
            //verificar se tem notificação no comand
            if (!comand.IsValid())
            {
                return(new ComandResult(false, "Por favor corrija os campos abaixo", comand.Notifications));
            }

            //verifica se o código ja existe
            var retorno = _repository.VerificarCodigoRecuperarSenha(comand.RecuperarSenha.ToString());

            if (retorno == null)
            {
                AddNotification("Código", "Código inválido!");
            }
            else
            {
                var      data = DateTime.Now;
                TimeSpan t    = data.Subtract(retorno.DataRecuperacao);

                if (t.TotalMinutes < 5)
                {
                    var chaveSenha = Functions.GetRandomString();
                    var _senha     = Crypto.EncriptarSenha(comand.Senha, chaveSenha);
                    retorno.TrocarSenha(_senha, chaveSenha);
                }
                else
                {
                    return(new ComandResult(false, "Tempo de troca de senha expirou,tenta novamente", Notifications));
                }
            }


            if (Invalid)
            {
                return(new ComandResult(false, "Por favor corrija os campos abaixo", Notifications));
            }

            if (!Invalid)
            {
                _repository.Alterar(retorno);
            }

            var resultato = new ComandResult(true, "Senha alterada com sucesso ", new { });

            if (resultato.Success)
            {
                var enviou = _enviarEmailServices.EnviarCodigo("*****@*****.**", new List <string>()
                {
                    retorno.Login
                }, "*****@*****.**", null, true, "teste", "<html><body><h1>Sua senha foi alterada com sucesso!!</h1></body></html>", "smtp.gmail.com");
                if (enviou)
                {
                    return(resultato);
                }
            }
            else
            {
                AddNotification("Erro", "Erro em alterar a senha,tente novamente!");
            }

            return(new ComandResult(false, "Falha em enviar o e-email,tente novamente!", Notifications));
        }