7
7
namespace Magento \Sales \Controller \AbstractController ;
8
8
9
9
use Magento \Framework \App \Action ;
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Magento \Framework \Data \Form \FormKey \Validator ;
10
12
use Magento \Framework \Registry ;
13
+ use Magento \Framework \Exception \NotFoundException ;
14
+ use Magento \Framework \Controller \ResultFactory ;
11
15
12
16
abstract class Reorder extends Action \Action
13
17
{
@@ -21,18 +25,26 @@ abstract class Reorder extends Action\Action
21
25
*/
22
26
protected $ _coreRegistry ;
23
27
28
+ /**
29
+ * @var Validator
30
+ */
31
+ private $ formKeyValidator ;
32
+
24
33
/**
25
34
* @param Action\Context $context
26
35
* @param OrderLoaderInterface $orderLoader
27
36
* @param Registry $registry
37
+ * @param Validator|null $formKeyValidator
28
38
*/
29
39
public function __construct (
30
40
Action \Context $ context ,
31
41
OrderLoaderInterface $ orderLoader ,
32
- Registry $ registry
42
+ Registry $ registry ,
43
+ Validator $ formKeyValidator = null
33
44
) {
34
45
$ this ->orderLoader = $ orderLoader ;
35
46
$ this ->_coreRegistry = $ registry ;
47
+ $ this ->formKeyValidator = $ formKeyValidator ?: ObjectManager::getInstance ()->create (Validator::class);
36
48
parent ::__construct ($ context );
37
49
}
38
50
@@ -43,6 +55,20 @@ public function __construct(
43
55
*/
44
56
public function execute ()
45
57
{
58
+ if ($ this ->getRequest ()->isPost ()) {
59
+ if (!$ this ->formKeyValidator ->validate ($ this ->getRequest ())) {
60
+ $ this ->messageManager ->addErrorMessage (__ ('Invalid Form Key. Please refresh the page. ' ));
61
+
62
+ /** @var \Magento\Framework\Controller\Result\Redirect $redirect */
63
+ $ redirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
64
+ $ redirect ->setPath ('*/*/history ' );
65
+
66
+ return $ redirect ;
67
+ }
68
+ } else {
69
+ throw new NotFoundException (__ ('Page not found. ' ));
70
+ }
71
+
46
72
$ result = $ this ->orderLoader ->load ($ this ->_request );
47
73
if ($ result instanceof \Magento \Framework \Controller \ResultInterface) {
48
74
return $ result ;
0 commit comments