@@ -46,6 +46,55 @@ public function __construct(IsCaptchaEnabledInterface $isEnabled, ValidationConf
46
46
$ this ->configResolver = $ configResolver ;
47
47
}
48
48
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
+
49
98
/**
50
99
* @inheritDoc
51
100
*/
@@ -55,38 +104,19 @@ public function getConfigFor(EndpointInterface $endpoint): ?ValidationConfigInte
55
104
$ serviceMethod = $ endpoint ->getServiceMethod ();
56
105
57
106
//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 ' )
73
109
|| $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\GenerateCustomerToken '
74
110
) {
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 ' )
82
114
|| $ serviceClass === 'Magento\CustomerGraphQl\Model\Resolver\CreateCustomer '
83
115
) {
84
- if ($ this ->isEnabled ->isCaptchaEnabledFor (self ::CREATE_CAPTCHA_ID )) {
85
- return $ this ->configResolver ->get (self ::CREATE_CAPTCHA_ID );
86
- }
116
+ return $ this ->validateCreateCustomerCaptcha ();
87
117
}
88
118
//phpcs:enable Magento2.PHP.LiteralNamespaces
89
119
90
- return null ;
120
+ return $ this -> validateChangePasswordCaptcha ( $ serviceMethod , $ serviceClass ) ;
91
121
}
92
122
}
0 commit comments