Commit 047ffad2 authored by Tino Goratsch's avatar Tino Goratsch

added a first rough version of reCAPTCHA

parent 1743fb73
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Captcha\Extension;
use ACP3\Core\I18n\Translator;
use ACP3\Core\View;
use ACP3\Modules\ACP3\Users\Model\UserModel;
class ReCaptchaCaptchaExtension implements CaptchaExtensionInterface
{
/**
* @var Translator
*/
private $translator;
/**
* @var View
*/
private $view;
/**
* @var UserModel
*/
private $user;
/**
* ReCaptchaCaptchaExtension constructor.
* @param Translator $translator
* @param View $view
* @param UserModel $user
*/
public function __construct(Translator $translator, View $view, UserModel $user)
{
$this->translator = $translator;
$this->view = $view;
$this->user = $user;
}
/**
* @inheritdoc
*/
public function getCaptchaName()
{
return $this->translator->t('captcha', 'recaptcha');
}
/**
* @inheritdoc
*/
public function getCaptcha(
$captchaLength = self::CAPTCHA_DEFAULT_LENGTH,
$formFieldId = self::CAPTCHA_DEFAULT_INPUT_ID,
$inputOnly = false,
$path = ''
) {
if (!$this->user->isAuthenticated()) {
$this->view->assign('captcha', [
'id' => $formFieldId,
'input_only' => $inputOnly,
'sitekey' => '',
'language' => $this->translator->getShortIsoCode()
]);
return $this->view->fetchTemplate('Captcha/Partials/captcha_recaptcha.tpl');
}
return '';
}
/**
* @inheritdoc
*/
public function isCaptchaValid($formData, $formFieldName, array $extra = [])
{
return true;
}
}
{extends file="asset:System/Partials/form_group.base.tpl"}
{$required=true}
{if !$captcha.input_only}
{$label={lang t="captcha|captcha"}}
{else}
{$cssSelector=''}
{/if}
{block FORM_GROUP_LABEL_ID}for="{$captcha.id}"{/block}
{block FORM_GROUP_FORM_FIELD}
<div class="g-recaptcha" data-sitekey="{$captcha.sitekey}"></div>
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl={$captcha.language}"></script>
{/block}
services:
captcha.extension.captcha:
class: ACP3\Modules\ACP3\Captcha\Extension\CaptchaExtensionInterface
factory: 'captcha.extension.captcha_factory:create'
captcha.extension.captcha_factory:
class: ACP3\Modules\ACP3\Captcha\Extension\CaptchaFactory
arguments:
- '@core.config'
- '@service_container'
captcha.extension.native_captcha_extension:
class: ACP3\Modules\ACP3\Captcha\Extension\NativeCaptchaExtension
arguments:
......@@ -13,12 +23,12 @@ services:
tags:
- { name: 'captcha.extension.captcha' }
captcha.extension.captcha_factory:
class: ACP3\Modules\ACP3\Captcha\Extension\CaptchaFactory
captcha.extension.recaptcha_captcha_extension:
class: ACP3\Modules\ACP3\Captcha\Extension\ReCaptchaCaptchaExtension
arguments:
- '@core.config'
- '@service_container'
- '@core.lang'
- '@core.view'
- '@users.model.user_model'
tags:
- { name: 'captcha.extension.captcha' }
captcha.extension.captcha:
class: ACP3\Modules\ACP3\Captcha\Extension\CaptchaExtensionInterface
factory: 'captcha.extension.captcha_factory:create'
......@@ -11,6 +11,7 @@
<item key="invalid_captcha_entered">Entweder wurde das Captcha falsch eingegeben oder es ist nicht mehr gültig.</item>
<item key="mod_description">Captchas bieten wirkungsvollen Schutz gegen Spambots.</item>
<item key="native">ACP3-Nativ</item>
<item key="recaptcha">reCAPTCHA</item>
<item key="select_captcha_type">Bitte wählen Sie den zu verwendenten Captcha-Typen aus.</item>
</keys>
</language>
......@@ -11,6 +11,7 @@
<item key="invalid_captcha_entered">Either the captcha is incorrect, or it is no longer valid.</item>
<item key="mod_description">Captchas provide effective protection against spambots.</item>
<item key="native">ACP3 native</item>
<item key="recaptcha">reCAPTCHA</item>
<item key="select_captcha_type">Please select the captcha type which should be used.</item>
</keys>
</language>
......@@ -22,7 +22,8 @@
"acp3/module-errors": "^4.7.1",
"acp3/module-permissions": "^4.7.1",
"acp3/module-system": "^4.7.1",
"acp3/module-users": "^4.7.1"
"acp3/module-users": "^4.7.1",
"google/recaptcha": "^1.1.0",
},
"autoload": {
"psr-4": {
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "a6846492e3ea46b99ec8605054ad1687",
"content-hash": "dc390a5475a207eaa46de905be66dcac",
"packages": [
{
"name": "ckeditor/ckeditor",
......@@ -715,6 +715,51 @@
],
"time": "2016-02-02T12:07:34+00:00"
},
{
"name": "google/recaptcha",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/google/recaptcha.git",
"reference": "5a56d15ca10a7b75158178752b2ad8f755eb4f78"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/recaptcha/zipball/5a56d15ca10a7b75158178752b2ad8f755eb4f78",
"reference": "5a56d15ca10a7b75158178752b2ad8f755eb4f78",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"ReCaptcha\\": "src/ReCaptcha"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Client library for reCAPTCHA, a free service that protect websites from spam and abuse.",
"homepage": "http://www.google.com/recaptcha/",
"keywords": [
"Abuse",
"captcha",
"recaptcha",
"spam"
],
"time": "2017-03-09T18:44:34+00:00"
},
{
"name": "guzzle/guzzle",
"version": "v3.8.1",
......
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