3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Captcha \Controller \Refresh ;
7
9
8
10
use Magento \Captcha \Helper \Data as CaptchaHelper ;
@@ -68,6 +70,26 @@ public function __construct(
68
70
* @inheritdoc
69
71
*/
70
72
public function execute ()
73
+ {
74
+ $ formId = $ this ->getRequestFormId ();
75
+
76
+ $ captchaModel = $ this ->captchaHelper ->getCaptcha ($ formId );
77
+ $ captchaModel ->generate ();
78
+
79
+ $ block = $ this ->layout ->createBlock ($ captchaModel ->getBlockName ());
80
+ $ block ->setFormId ($ formId )->setIsAjax (true )->toHtml ();
81
+
82
+ $ result = $ this ->jsonResultFactory ->create ();
83
+
84
+ return $ result ->setData (['imgSrc ' => $ captchaModel ->getImgSrc ()]);
85
+ }
86
+
87
+ /**
88
+ * Returns requested Form ID
89
+ *
90
+ * @return string|null
91
+ */
92
+ private function getRequestFormId (): ?string
71
93
{
72
94
$ formId = $ this ->request ->getPost ('formId ' );
73
95
if (null === $ formId ) {
@@ -76,15 +98,10 @@ public function execute()
76
98
if ($ content ) {
77
99
$ params = $ this ->serializer ->unserialize ($ content );
78
100
}
79
- $ formId = isset ($ params ['formId ' ]) ? $ params ['formId ' ] : null ;
80
- }
81
- $ captchaModel = $ this ->captchaHelper ->getCaptcha ($ formId );
82
- $ captchaModel ->generate ();
83
101
84
- $ block = $ this -> layout -> createBlock ( $ captchaModel -> getBlockName ()) ;
85
- $ block -> setFormId ( $ formId )-> setIsAjax ( true )-> toHtml ();
102
+ $ formId = $ params [ ' formId ' ] ?? null ;
103
+ }
86
104
87
- $ result = $ this ->jsonResultFactory ->create ();
88
- return $ result ->setData (['imgSrc ' => $ captchaModel ->getImgSrc ()]);
105
+ return $ formId !== null ? (string )$ formId : null ;
89
106
}
90
107
}
0 commit comments