Commit 138fbd8e authored by Tino Goratsch's avatar Tino Goratsch

Squashed 'ACP3/Modules/ACP3/Captcha/' content from commit ffea2ba

git-subtree-dir: ACP3/Modules/ACP3/Captcha
git-subtree-split: ffea2bab08f17a2dbfc4355877c8b797a62a4c41
parents
.idea
vendor/
<?php
namespace ACP3\Modules\ACP3\Captcha\Controller;
use ACP3\Core;
/**
* Class Index
* @package ACP3\Modules\ACP3\Captcha\Controller
*/
class Index extends Core\Modules\Controller\Frontend
{
public function actionImage()
{
$this->setNoOutput(true);
if (!empty($this->request->path) &&
isset($_SESSION['captcha_' . $this->request->path])
) {
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: image/gif');
$captcha = $_SESSION['captcha_' . $this->request->path];
$captchaLength = strlen($captcha);
$width = $captchaLength * 25;
$height = 30;
$im = imagecreate($width, $height);
// Hintergrundfarbe
imagecolorallocate($im, 255, 255, 255);
$textColor = imagecolorallocate($im, 0, 0, 0);
for ($i = 0; $i < $captchaLength; ++$i) {
$font = mt_rand(2, 5);
$posLeft = 22 * $i + 10;
$posTop = mt_rand(1, $height - imagefontheight($font) - 3);
imagestring($im, $font, $posLeft, $posTop, $captcha[$i], $textColor);
}
imagegif($im);
imagedestroy($im);
}
}
}
<?php
namespace ACP3\Modules\ACP3\Captcha;
use ACP3\Core;
/**
* Class Helpers
* @package ACP3\Modules\ACP3\Captcha
*/
class Helpers
{
/**
* @var \ACP3\Core\Auth
*/
protected $auth;
/**
* @var \ACP3\Core\Helpers\Secure
*/
protected $secureHelper;
/**
* @var \ACP3\Core\Request
*/
protected $request;
/**
* @var \ACP3\Core\Router
*/
protected $router;
/**
* @var \ACP3\Core\View
*/
protected $view;
/**
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\Request $request
* @param \ACP3\Core\Router $router
* @param \ACP3\Core\View $view
* @param \ACP3\Core\Helpers\Secure $secureHelper
*/
public function __construct(
Core\Auth $auth,
Core\Request $request,
Core\Router $router,
Core\View $view,
Core\Helpers\Secure $secureHelper
) {
$this->auth = $auth;
$this->request = $request;
$this->router = $router;
$this->view = $view;
$this->secureHelper = $secureHelper;
}
/**
* Erzeugt das Captchafeld für das Template
*
* @param integer $captchaLength
* Anzahl der Zeichen, welche das Captcha haben soll
* @param string $id
* @param bool $inputOnly
* @param string $path
*
* @return string
*/
public function captcha($captchaLength = 5, $id = 'captcha', $inputOnly = false, $path = '')
{
// Wenn man als User angemeldet ist, Captcha nicht anzeigen
if ($this->auth->isUser() === false) {
$path = sha1($this->router->route(empty($path) === true ? $this->request->query : $path));
$_SESSION['captcha_' . $path] = $this->secureHelper->salt($captchaLength);
$captcha = [];
$captcha['width'] = $captchaLength * 25;
$captcha['id'] = $id;
$captcha['height'] = 30;
$captcha['input_only'] = $inputOnly;
$captcha['path'] = $path;
$this->view->assign('captcha', $captcha);
return $this->view->fetchTemplate('captcha/captcha.tpl');
}
return '';
}
}
<?php
namespace ACP3\Modules\ACP3\Captcha;
use ACP3\Core\Modules;
/**
* Class Installer
* @package ACP3\Modules\ACP3\Captcha
*/
class Installer extends Modules\AbstractInstaller
{
const MODULE_NAME = 'captcha';
const SCHEMA_VERSION = 31;
/**
* @inheritdoc
*/
public function createTables()
{
return [];
}
/**
* @inheritdoc
*/
public function removeTables()
{
return [];
}
/**
* @inheritdoc
*/
public function settings()
{
return [];
}
/**
* @inheritdoc
*/
public function schemaUpdates()
{
return [
31 => [
"DELETE FROM `{pre}acl_resources` WHERE `module_id` = " . $this->getModuleId() . " AND `page` = \"functions\";",
]
];
}
}
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<language>
<info>
<name>Deutsch (Deutschland)</name>
<direction>ltr</direction>
</info>
<keys>
<item key="captcha">Captcha</item>
<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>
</keys>
</language>
<?xml version="1.0" encoding="UTF-8"?>
<language>
<info>
<name>English (United States)</name>
<direction>ltr</direction>
</info>
<keys>
<item key="captcha">Captcha</item>
<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>
</keys>
</language>
{if $captcha.input_only === true}
<div class="input-group input-group-lg">
<span class="input-group-addon" style="padding-top: 5px; padding-bottom: 5px">
<img src="{uri args="captcha/index/image/path_`$captcha.path`"}" width="{$captcha.width}" height="{$captcha.height}" alt="">
</span>
<input class="form-control input-lg" type="text" name="captcha" id="{$captcha.id}" value="" required>
</div>
{else}
<div class="form-group">
<label for="{$captcha.id}" class="col-sm-2 control-label">{lang t="captcha|captcha"}</label>
<div class="col-sm-10">
<div class="input-group input-group-lg">
<span class="input-group-addon" style="padding-top: 5px; padding-bottom: 5px">
<img src="{uri args="captcha/index/image/path_`$captcha.path`"}" width="{$captcha.width}" height="{$captcha.height}" alt="">
</span>
<input class="form-control input-lg" type="text" name="captcha" id="{$captcha.id}" value="" required>
</div>
</div>
</div>
{/if}
\ No newline at end of file
{
"name": "acp3/module-captcha",
"type": "acp3-module",
"require": {
"acp3/composer-installer": "*"
},
"extra": {
"installer-name": "ACP3/Captcha"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module>
<info>
<name lang="true"/>
<description lang="true"/>
<author>Tino Goratsch</author>
<version core="true"/>
</info>
</module>
parameters:
captcha.controller.frontend.index.fqdn: 'ACP3\Modules\ACP3\Captcha\Controller\Index'
captcha.helpers.fqdn: 'ACP3\Modules\ACP3\Captcha\Helpers'
captcha.installer.fqdn: 'ACP3\Modules\ACP3\Captcha\Installer'
services:
captcha.controller.frontend.index:
class: %captcha.controller.frontend.index.fqdn%
parent: core.modules.controller.frontend
captcha.helpers:
class: %captcha.helpers.fqdn%
arguments: ['@core.auth', '@core.request', '@core.router', '@core.view', '@core.helpers.secure']
captcha.installer:
class: %captcha.installer.fqdn%
parent: core.modules.abstractInstaller
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