reCaptcha works without javascript now
This commit is contained in:
@ -13,8 +13,11 @@ function ( // eslint-disable-line func-names
|
|||||||
var sitekey = $(this).attr('data-sitekey');
|
var sitekey = $(this).attr('data-sitekey');
|
||||||
var container = $(this).find('> .mailpoet_recaptcha_container').get(0);
|
var container = $(this).find('> .mailpoet_recaptcha_container').get(0);
|
||||||
var field = $(this).find('> .mailpoet_recaptcha_field');
|
var field = $(this).find('> .mailpoet_recaptcha_field');
|
||||||
var widgetId = window.grecaptcha.render(container, { sitekey: sitekey, size: 'compact' });
|
var widgetId;
|
||||||
|
if (sitekey) {
|
||||||
|
widgetId = window.grecaptcha.render(container, { sitekey: sitekey, size: 'compact' });
|
||||||
field.val(widgetId);
|
field.val(widgetId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -66,7 +69,7 @@ function ( // eslint-disable-line func-names
|
|||||||
}).join('<br />')
|
}).join('<br />')
|
||||||
).show();
|
).show();
|
||||||
}).done(function (response) { // eslint-disable-line func-names
|
}).done(function (response) { // eslint-disable-line func-names
|
||||||
if (window.grecaptcha) {
|
if (window.grecaptcha && formData.recaptcha) {
|
||||||
window.grecaptcha.reset(formData.recaptcha);
|
window.grecaptcha.reset(formData.recaptcha);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
@ -88,7 +91,7 @@ function ( // eslint-disable-line func-names
|
|||||||
// reset validation
|
// reset validation
|
||||||
parsley.reset();
|
parsley.reset();
|
||||||
// reset captcha
|
// reset captcha
|
||||||
if (window.grecaptcha) {
|
if (window.grecaptcha && formData.recaptcha) {
|
||||||
window.grecaptcha.reset(formData.recaptcha);
|
window.grecaptcha.reset(formData.recaptcha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,17 +90,18 @@ class Subscribers extends APIEndpoint {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($recaptcha['enabled']) && !isset($data['recaptcha'])) {
|
if(!empty($recaptcha['enabled']) && empty($data['recaptcha'])) {
|
||||||
return $this->badRequest(array(
|
return $this->badRequest(array(
|
||||||
APIError::BAD_REQUEST => __('Please check the captcha.', 'mailpoet')
|
APIError::BAD_REQUEST => __('Please check the captcha.', 'mailpoet')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($recaptcha['enabled'])) {
|
if(!empty($recaptcha['enabled'])) {
|
||||||
|
$res = empty($data['recaptcha']) ? $data['recaptcha-no-js'] : $data['recaptcha'];
|
||||||
$res = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', array(
|
$res = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', array(
|
||||||
'body' => array(
|
'body' => array(
|
||||||
'secret' => $recaptcha['secret_token'],
|
'secret' => $recaptcha['secret_token'],
|
||||||
'response' => $data['recaptcha']
|
'response' => $res
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
if(is_wp_error($res)) {
|
if(is_wp_error($res)) {
|
||||||
@ -125,7 +126,6 @@ class Subscribers extends APIEndpoint {
|
|||||||
$segment_ids = $form->filterSegments($segment_ids);
|
$segment_ids = $form->filterSegments($segment_ids);
|
||||||
unset($data['segments']);
|
unset($data['segments']);
|
||||||
|
|
||||||
|
|
||||||
if(empty($segment_ids)) {
|
if(empty($segment_ids)) {
|
||||||
return $this->badRequest(array(
|
return $this->badRequest(array(
|
||||||
APIError::BAD_REQUEST => __('Please select a list.', 'mailpoet')
|
APIError::BAD_REQUEST => __('Please select a list.', 'mailpoet')
|
||||||
|
@ -50,6 +50,20 @@ class Renderer {
|
|||||||
$site_key = Setting::getValue('re_captcha.site_token');
|
$site_key = Setting::getValue('re_captcha.site_token');
|
||||||
$html .= '<div class="mailpoet_recaptcha" data-sitekey="'. $site_key .'">
|
$html .= '<div class="mailpoet_recaptcha" data-sitekey="'. $site_key .'">
|
||||||
<div class="mailpoet_recaptcha_container"></div>
|
<div class="mailpoet_recaptcha_container"></div>
|
||||||
|
<noscript>
|
||||||
|
<div>
|
||||||
|
<div style="width: 302px; height: 422px; position: relative;">
|
||||||
|
<div style="width: 302px; height: 422px; position: absolute;">
|
||||||
|
<iframe src="https://www.google.com/recaptcha/api/fallback?k='. $site_key .'" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;">
|
||||||
|
</iframe>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="width: 300px; height: 60px; border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;">
|
||||||
|
<textarea id="g-recaptcha-response" name="data[recaptcha]" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none;" >
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</noscript>
|
||||||
<input class="mailpoet_recaptcha_field" type="hidden" name="recaptcha">
|
<input class="mailpoet_recaptcha_field" type="hidden" name="recaptcha">
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user