Magento 2-debug.log-main.DEBUG:操作"Vendor \ Module \ Controller \ Index \ Post \ Interceptor"的请求验证失败 [英] Magento 2 -- debug.log -- main.DEBUG: Request validation failed for action "Vendor\Module\Controller\Index\Post\Interceptor"

查看:118
本文介绍了Magento 2-debug.log-main.DEBUG:操作"Vendor \ Module \ Controller \ Index \ Post \ Interceptor"的请求验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个自定义模块,该模块实质上具有与默认的Magento 2联系人表格相同的功能.我收到一个非常恼人的错误,似乎无法找到解决方法.看来我的POST请求未通过Magento的请求验证,但是我不确定如何找到更多特定信息.

I'm implementing a Custom Module that essentially has the same functionality as the default Magento 2 Contact Form. I'm receiving a very irritating error I can't seem to find a solution to. It seems my POST request is failing Magento's request validation, but I'm not sure how to find any more specific information.

我尝试实现一个绕过Magento CSRF验证的"CSRFSkip"插件.我尝试更改控制器扩展和实现的内容.我已经广泛搜索了日志.

I've attempted to implement a "CSRFSkip" plugin that bypasses the Magento CSRF validation. I've tried changing what my controller extends and implements. I've searched the logs extensively.

这是我的Magento debug.log,因为发生了错误.

Here's my Magento debug.log as the error is happening.

[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 [] []

这是我的控制器. /供应商/模块/控制器/索引/Post.php

Here's my controller. /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;
    }
}

我希望我的发布功能能够运行并发送我的电子邮件.

I expect for my post function to run and dispatch my email.

实际发生的是重定向到我的表单页面,以及日志中一些与验证相关的错误.

What actually happens is a redirect to my form page, and some validation related errors in the logs.

推荐答案

可以检查var,生成和pub文件夹的权限吗?使用root用户部署更改时,权限可能会更改为644,从而导致此类问题.

Can you check the permissions for var, generated and pub folders? When using root user for deploying changes the permissions can change to 644 causing these type of issues.

这篇关于Magento 2-debug.log-main.DEBUG:操作"Vendor \ Module \ Controller \ Index \ Post \ Interceptor"的请求验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆