Magento 2 - debug.log - main.DEBUG: Не удалось выполнить проверку запроса для действия "Vendor \ Module \ Controller \ Index \ Post \ Interceptor" - PullRequest
0 голосов
/ 17 октября 2019

Я внедряю пользовательский модуль, который по сути имеет те же функции, что и стандартная контактная форма Magento 2. Я получаю очень раздражающую ошибку, которую я не могу найти решение. Похоже, мой POST-запрос не проходит проверку запроса Magento, но я не уверен, как найти более конкретную информацию.

Я попытался реализовать плагин "CSRFSkip", который обходит проверку Magento CSRF. Я попытался изменить то, что мой контроллер расширяет и реализует. Я много раз просматривал журналы.

Вот мой Magento debug.log, когда происходит ошибка.

[2019-10-17 19:39:16] main.DEBUG: Request validation failed for action "Vendor\Module\Controller\Index\Post\Interceptor" [] []
[2019-10-17 19:41:20] main.DEBUG: Request validation failed for action "Vendor\Module\Controller\Index\Post\Interceptor" [] []
[2019-10-17 19:41:21] main.INFO: Broken reference: the 'catalog.compare.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2019-10-17 19:41:21] main.INFO: Broken reference: the 'sale.reorder.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2019-10-17 19:41:21] main.INFO: Broken reference: the 'wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []

Вот мой контроллер. /Vendor/Module/Controller/Index/Post.php

<?php

namespace Vendor\Module\Controller\Index;

use Magento\Framework\Controller\ResultFactory;

class Post extends \Magento\Framework\App\Action\Action implements \Magento\Framework\App\Action\HttpPostActionInterface
{
    /**
     * Post action
     *
     * @return void
     */
    public function execute()
    {
        $post = $this->getRequest()->getPostValue();
        if (!$post['name']) {
            $this->_redirect('/find-a-dealer');
            return;
        }

        $this->inlineTranslation->suspend();
        try {
            $postObject = new \Magento\Framework\DataObject();
            $postObject->setData($post);
            $error = false;

            $this->logger->debug($post['name']);
            if (!\Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
                $error = true;
            }

            $this->logger->debug($post['email']);
            if (!\Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                $error = true;
            }

            $this->logger->debug($post['city']);
            if (!\Zend_Validate::is(trim($post['city']), 'NotEmpty')) {
                $error = true;
            }

            $this->logger->debug($post['state']);
            if (!\Zend_Validate::is(trim($post['state']), 'NotEmpty')) {
                $error = true;
            }

            $this->logger->debug($post['zip']);
            if (!\Zend_Validate::is(trim($post['zip']), 'NotEmpty')) {
                $error = true;
            }

            $this->logger->debug($post['part']);
            if (!\Zend_Validate::is(trim($post['part']), 'NotEmpty')) {
                $error = true;
            }

            if ($error) {
                throw new \Exception();
            }

            $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
            $transport = $this->_transportBuilder
                ->setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, $storeScope))
                ->setTemplateOptions(
                    [
                        'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
                        'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                    ]
                )
                ->setTemplateVars(['data' => $postObject])
                ->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))
                ->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))
                ->setReplyTo($post['email'])
                ->getTransport();

            $transport->sendMessage();

            $this->inlineTranslation->resume();
            $this->messageManager->addSuccess(
                __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
            );
            $this->getDataPersistor()->clear('find-a-dealer');
            $this->_redirect('find-a-dealer');
            return;
        } catch (\Exception $e) {
            $this->inlineTranslation->resume();
            $this->messageManager->addError(
                __('We can\'t process your request right now. Sorry, that\'s all we know.')
            );
            $this->getDataPersistor()->set('find-a-dealer', $post);
            $this->_redirect('find-a-dealer');
            return;
        }
    }

    /**
     * Get Data Persistor
     *
     * @return DataPersistorInterface
     */
    private function getDataPersistor()
    {
        if ($this->dataPersistor === null) {
            $this->dataPersistor = ObjectManager::getInstance()
                ->get(DataPersistorInterface::class);
        }

        return $this->dataPersistor;
    }
}

Я ожидаю, что моя функция публикации запустит и отправит мою электронную почту.

На самом деле происходит перенаправление на мою страницу формыи некоторые ошибки, связанные с проверкой в ​​журналах.

1 Ответ

0 голосов
/ 17 октября 2019

Можете ли вы проверить разрешения для папок var, созданных и pub? При использовании пользователя root для развертывания изменений разрешения могут измениться на 644, вызывая проблемы такого типа.

...