@@ -46,6 +46,55 @@ public function __construct(IsCaptchaEnabledInterface $isEnabled, ValidationConf
4646 $ this ->configResolver = $ configResolver ;
4747 }
4848
49+ /**
50+ * Validates ifChangedPasswordCaptchaEnabled using captcha_id
51+ *
52+ * @param string $serviceMethod
53+ * @param string $serviceClass
54+ * @return ValidationConfigInterface|null
55+ */
56+ private function validateChangePasswordCaptcha ($ serviceMethod , $ serviceClass ): ?ValidationConfigInterface
57+ {
58+ //phpcs:disable Magento2.PHP.LiteralNamespaces
59+ if ($ serviceMethod === 'resetPassword ' || $ serviceMethod === 'initiatePasswordReset '
60+ || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\ResetPassword '
61+ || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\RequestPasswordResetEmail '
62+ ) {
63+ return $ this ->isEnabled ->isCaptchaEnabledFor (self ::RESET_PASSWORD_CAPTCHA_ID ) ?
64+ $ this ->configResolver ->get (self ::RESET_PASSWORD_CAPTCHA_ID ) : null ;
65+ } elseif ($ serviceMethod === 'changePasswordById '
66+ || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\ChangePassword '
67+ ) {
68+ return $ this ->isEnabled ->isCaptchaEnabledFor (self ::CHANGE_PASSWORD_CAPTCHA_ID ) ?
69+ $ this ->configResolver ->get (self ::CHANGE_PASSWORD_CAPTCHA_ID ) : null ;
70+ }
71+ //phpcs:enable Magento2.PHP.LiteralNamespaces
72+
73+ return null ;
74+ }
75+
76+ /**
77+ * Validates ifLoginCaptchaEnabled using captcha_id
78+ *
79+ * @return ValidationConfigInterface|null
80+ */
81+ private function validateLoginCaptcha (): ?ValidationConfigInterface
82+ {
83+ return $ this ->isEnabled ->isCaptchaEnabledFor (self ::LOGIN_CAPTCHA_ID ) ?
84+ $ this ->configResolver ->get (self ::LOGIN_CAPTCHA_ID ) : null ;
85+ }
86+
87+ /**
88+ * Validates ifCreateCustomerCaptchaEnabled using captcha_id
89+ *
90+ * @return ValidationConfigInterface|null
91+ */
92+ private function validateCreateCustomerCaptcha (): ?ValidationConfigInterface
93+ {
94+ return $ this ->isEnabled ->isCaptchaEnabledFor (self ::CREATE_CAPTCHA_ID ) ?
95+ $ this ->configResolver ->get (self ::CREATE_CAPTCHA_ID ) : null ;
96+ }
97+
4998 /**
5099 * @inheritDoc
51100 */
@@ -55,38 +104,19 @@ public function getConfigFor(EndpointInterface $endpoint): ?ValidationConfigInte
55104 $ serviceMethod = $ endpoint ->getServiceMethod ();
56105
57106 //phpcs:disable Magento2.PHP.LiteralNamespaces
58- if ($ serviceMethod === 'resetPassword '
59- || $ serviceMethod === 'initiatePasswordReset '
60- || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\ResetPassword ' ) {
61- if ($ this ->isEnabled ->isCaptchaEnabledFor (self ::RESET_PASSWORD_CAPTCHA_ID )) {
62- return $ this ->configResolver ->get (self ::RESET_PASSWORD_CAPTCHA_ID );
63- }
64- } elseif ($ serviceMethod === 'changePasswordById '
65- || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\ChangePassword ' ) {
66- if ($ this ->isEnabled ->isCaptchaEnabledFor (self ::CHANGE_PASSWORD_CAPTCHA_ID )) {
67- return $ this ->configResolver ->get (self ::CHANGE_PASSWORD_CAPTCHA_ID );
68- }
69- } elseif (
70- ($ serviceClass === 'Magento\Integration\Api\CustomerTokenServiceInterface '
71- && $ serviceMethod === 'createCustomerAccessToken '
72- )
107+ if (($ serviceClass === 'Magento\Integration\Api\CustomerTokenServiceInterface '
108+ && $ serviceMethod === 'createCustomerAccessToken ' )
73109 || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\GenerateCustomerToken '
74110 ) {
75- if ($ this ->isEnabled ->isCaptchaEnabledFor (self ::LOGIN_CAPTCHA_ID )) {
76- return $ this ->configResolver ->get (self ::LOGIN_CAPTCHA_ID );
77- }
78- } elseif (
79- ($ serviceClass === 'Magento\Customer\Api\AccountManagementInterface '
80- && $ serviceMethod === 'createAccount '
81- )
111+ return $ this ->validateLoginCaptcha ();
112+ } elseif (($ serviceClass === 'Magento\Customer\Api\AccountManagementInterface '
113+ && $ serviceMethod === 'createAccount ' )
82114 || $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\CreateCustomer '
83115 ) {
84- if ($ this ->isEnabled ->isCaptchaEnabledFor (self ::CREATE_CAPTCHA_ID )) {
85- return $ this ->configResolver ->get (self ::CREATE_CAPTCHA_ID );
86- }
116+ return $ this ->validateCreateCustomerCaptcha ();
87117 }
88118 //phpcs:enable Magento2.PHP.LiteralNamespaces
89119
90- return null ;
120+ return $ this -> validateChangePasswordCaptcha ( $ serviceMethod , $ serviceClass ) ;
91121 }
92122}
0 commit comments