Commit e416345f authored by Tino Goratsch's avatar Tino Goratsch

Merge branch 'feature/nocaptcha' into develop

parents 96443415 aabc0dfd
......@@ -59,17 +59,27 @@ class RenderRecaptchaOnLayoutContentBeforeListener
'sitekey' => $settings['recaptcha_sitekey'],
'lang' => $this->translator->getShortIsoCode()
]);
$this->view->displayTemplate('Captcha/Partials/captcha_recaptcha.onload.tpl');
$this->view->displayTemplate($this->getServiceIdTemplateMap()[$settings['captcha']]);
}
}
/**
* @return array
*/
private function getServiceIdTemplateMap()
{
return [
'captcha.extension.recaptcha_captcha_extension' => 'Captcha/Partials/captcha_recaptcha.onload.tpl',
];
}
/**
* @param array $settings
* @return bool
*/
private function isRecaptcha(array $settings)
{
return $settings['captcha'] === 'captcha.extension.recaptcha_captcha_extension'
return array_key_exists($settings['captcha'], $this->getServiceIdTemplateMap())
&& !empty($settings['recaptcha_sitekey'])
&& !empty($settings['recaptcha_secret']);
}
......
......@@ -16,6 +16,7 @@ use ReCaptcha\ReCaptcha;
class ReCaptchaCaptchaExtension implements CaptchaExtensionInterface
{
const TEMPLATE = 'Captcha/Partials/captcha_recaptcha.tpl';
/**
* @var Translator
*/
......@@ -77,13 +78,16 @@ class ReCaptchaCaptchaExtension implements CaptchaExtensionInterface
$path = ''
) {
if (!$this->user->isAuthenticated()) {
$settings = $this->settings->getSettings(Schema::MODULE_NAME);
$this->view->assign('captcha', [
'id' => $formFieldId,
'input_only' => $inputOnly,
'length' => $captchaLength
'length' => $captchaLength,
'sitekey' => $settings['recaptcha_sitekey']
]);
return $this->view->fetchTemplate('Captcha/Partials/captcha_recaptcha.tpl');
return $this->view->fetchTemplate(static::TEMPLATE);
}
return '';
......
......@@ -4,9 +4,12 @@
*/
jQuery(document).ready(function ($) {
var $recaptchaWrapper = $('#recaptcha-wrapper');
var $recaptchaWrapper = $('#recaptcha-wrapper'),
serviceIds = [
'captcha.extension.recaptcha_captcha_extension'
];
$('#captcha').on('change', function() {
$recaptchaWrapper.toggle(this.value === 'captcha.extension.recaptcha_captcha_extension');
$recaptchaWrapper.toggle(serviceIds.indexOf(this.value) !== -1);
}).filter(':selected').triggerHandler('change');
});
/*
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
var onloadCallback = function() {
jQuery('.recaptcha-placeholder').each(function() {
this.innerHtml = '';
grecaptcha.render(this.id, {
'sitekey': this.dataset.sitekey,
'size': this.dataset.size
});
});
};
{javascripts}
<script type="text/javascript">
var onloadCallback = function() {
jQuery('.recaptcha-placeholder').each(function() {
grecaptcha.render(this.id, {
'sitekey': '{$recaptcha.sitekey}',
'size': this.dataset.size
});
});
};
</script>
{include_js module="captcha" file="partials/recaptcha.onload"}
<script type="text/javascript"
src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&amp;render=explicit&amp;hl={$recaptcha.lang}"
async
......
......@@ -5,7 +5,8 @@
{$cssSelector=''}
{/if}
{block FORM_GROUP_LABEL_ID}for="{$captcha.id}"{/block}
{block FORM_GROUP_FORM_FIELD}
<div id="{$captcha.id}" class="recaptcha-placeholder"{if $captcha.length < 5} data-size="compact"{/if}></div>
<div id="{$captcha.id}"
class="recaptcha-placeholder"
data-sitekey="{$captcha.sitekey}"{if $captcha.length < 5} data-size="compact"{/if}></div>
{/block}
......@@ -12,6 +12,10 @@
<item key="mod_description">Captchas provide effective protection against spambots.</item>
<item key="native">ACP3 native</item>
<item key="recaptcha">reCAPTCHA</item>
<item key="recaptcha_secret">reCAPTCHA secret</item>
<item key="recaptcha_sitekey">reCAPTCHA sitekey</item>
<item key="select_captcha_type">Please select the captcha type which should be used.</item>
<item key="type_in_recaptcha_secret">Please type in the reCAPTCHA secret.</item>
<item key="type_in_recaptcha_sitekey">Please type in the reCAPTCHA sitekey.</item>
</keys>
</language>
......@@ -14,6 +14,7 @@
function Plugin(element, options) {
this.element = element;
this.isFormValid = true;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
......@@ -31,9 +32,9 @@
$(this.element).on('submit', function (e) {
e.preventDefault();
$(document).trigger('acp3.ajaxFrom.submit.before');
$(document).trigger('acp3.ajaxFrom.submit.before', [ that ]);
if (that.preValidateForm(that.element)) {
if (that.isFormValid && that.preValidateForm(that.element)) {
that.processAjaxRequest();
}
}).on('click', function (e) {
......@@ -51,8 +52,7 @@
});
},
preValidateForm: function (form) {
var field,
isValid = true;
var field;
this.removeAllPreviousErrors();
......@@ -67,13 +67,13 @@
this.addErrorDecorationToFormGroup($(field));
this.addErrorMessageToFormField($(field), field.validationMessage);
isValid = false;
this.isFormValid = false;
}
}
this.focusTabWithFirstErrorMessage();
return isValid;
return this.isFormValid;
},
removeAllPreviousErrors: function () {
$('form .form-group.has-error')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment