8
8
namespace Magento \ReCaptchaCustomer \Observer ;
9
9
10
10
use Magento \Framework \App \Action \Action ;
11
- use Magento \Framework \App \ActionFlag ;
12
- use Magento \Framework \App \ResponseInterface ;
13
11
use Magento \Framework \Event \Observer ;
14
12
use Magento \Framework \Event \ObserverInterface ;
15
13
use Magento \Framework \Exception \InputException ;
16
14
use Magento \Framework \Exception \LocalizedException ;
17
- use Magento \Framework \ Serialize \ SerializerInterface ;
15
+ use Magento \ReCaptchaCustomer \ Model \ AjaxLogin \ ErrorProcessor ;
18
16
use Magento \ReCaptchaUi \Model \CaptchaResponseResolverInterface ;
19
17
use Magento \ReCaptchaUi \Model \IsCaptchaEnabledInterface ;
20
18
use Magento \ReCaptchaUi \Model \ValidationConfigResolverInterface ;
@@ -41,16 +39,6 @@ class AjaxLoginObserver implements ObserverInterface
41
39
*/
42
40
private $ captchaValidator ;
43
41
44
- /**
45
- * @var ActionFlag
46
- */
47
- private $ actionFlag ;
48
-
49
- /**
50
- * @var SerializerInterface
51
- */
52
- private $ serializer ;
53
-
54
42
/**
55
43
* @var IsCaptchaEnabledInterface
56
44
*/
@@ -61,31 +49,33 @@ class AjaxLoginObserver implements ObserverInterface
61
49
*/
62
50
private $ logger ;
63
51
52
+ /**
53
+ * @var ErrorProcessor
54
+ */
55
+ private $ errorProcessor ;
56
+
64
57
/**
65
58
* @param CaptchaResponseResolverInterface $captchaResponseResolver
66
59
* @param ValidationConfigResolverInterface $validationConfigResolver
67
60
* @param ValidatorInterface $captchaValidator
68
- * @param ActionFlag $actionFlag
69
- * @param SerializerInterface $serializer
70
61
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
71
62
* @param LoggerInterface $logger
63
+ * @param ErrorProcessor $errorProcessor
72
64
*/
73
65
public function __construct (
74
66
CaptchaResponseResolverInterface $ captchaResponseResolver ,
75
67
ValidationConfigResolverInterface $ validationConfigResolver ,
76
68
ValidatorInterface $ captchaValidator ,
77
- ActionFlag $ actionFlag ,
78
- SerializerInterface $ serializer ,
79
69
IsCaptchaEnabledInterface $ isCaptchaEnabled ,
80
- LoggerInterface $ logger
70
+ LoggerInterface $ logger ,
71
+ ErrorProcessor $ errorProcessor
81
72
) {
82
73
$ this ->captchaResponseResolver = $ captchaResponseResolver ;
83
74
$ this ->validationConfigResolver = $ validationConfigResolver ;
84
75
$ this ->captchaValidator = $ captchaValidator ;
85
- $ this ->actionFlag = $ actionFlag ;
86
- $ this ->serializer = $ serializer ;
87
76
$ this ->isCaptchaEnabled = $ isCaptchaEnabled ;
88
77
$ this ->logger = $ logger ;
78
+ $ this ->errorProcessor = $ errorProcessor ;
89
79
}
90
80
91
81
/**
@@ -101,36 +91,27 @@ public function execute(Observer $observer): void
101
91
$ controller = $ observer ->getControllerAction ();
102
92
$ request = $ controller ->getRequest ();
103
93
$ response = $ controller ->getResponse ();
94
+
104
95
$ validationConfig = $ this ->validationConfigResolver ->get ($ key );
105
96
106
97
try {
107
98
$ reCaptchaResponse = $ this ->captchaResponseResolver ->resolve ($ request );
108
99
} catch (InputException $ e ) {
109
100
$ this ->logger ->error ($ e );
110
- $ this ->processError ($ response , $ validationConfig ->getValidationFailureMessage ());
101
+ $ this ->errorProcessor ->processError (
102
+ $ response ,
103
+ $ validationConfig ->getValidationFailureMessage ()
104
+ );
111
105
return ;
112
106
}
113
107
114
108
$ validationResult = $ this ->captchaValidator ->isValid ($ reCaptchaResponse , $ validationConfig );
115
109
if (false === $ validationResult ->isValid ()) {
116
- $ this ->processError ($ response , $ validationConfig ->getValidationFailureMessage ());
110
+ $ this ->errorProcessor ->processError (
111
+ $ response ,
112
+ $ validationConfig ->getValidationFailureMessage ()
113
+ );
117
114
}
118
115
}
119
116
}
120
-
121
- /**
122
- * @param ResponseInterface $response
123
- * @param string $message
124
- * @return void
125
- */
126
- private function processError (ResponseInterface $ response , string $ message ): void
127
- {
128
- $ this ->actionFlag ->set ('' , Action::FLAG_NO_DISPATCH , true );
129
-
130
- $ jsonPayload = $ this ->serializer ->serialize ([
131
- 'errors ' => true ,
132
- 'message ' => $ message ,
133
- ]);
134
- $ response ->representJson ($ jsonPayload );
135
- }
136
117
}
0 commit comments