mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Captcha service provider
This commit is contained in:
parent
90902119b6
commit
44f4b83cc2
3 changed files with 28 additions and 5 deletions
|
@ -66,6 +66,10 @@ $di->register(new \TorrentPier\ServiceProviders\TwigServiceProvider, [
|
|||
'config.twig.dir_cache' => $di->config->twig->dir_cache
|
||||
]);
|
||||
|
||||
$di->register(new \TorrentPier\ServiceProviders\CaptchaServiceProvider, [
|
||||
'config.captcha.secret_key' => $di->config->captcha->secret_key
|
||||
]);
|
||||
|
||||
$bb_cfg = $di->config->toArray();
|
||||
$page_cfg = $di->config->page->toArray();
|
||||
$tr_cfg = $di->config->tracker->toArray();
|
||||
|
|
|
@ -2608,13 +2608,11 @@ function bb_captcha ($mode, $callback = '')
|
|||
$public = $di->config->get('captcha.public_key');
|
||||
$cp_theme = $di->config->get('captcha.theme');
|
||||
|
||||
if (!$public || !$secret)
|
||||
if (!$public && !$secret)
|
||||
{
|
||||
bb_die($lang['CAPTCHA_SETTINGS']);
|
||||
}
|
||||
|
||||
$reCaptcha = new \ReCaptcha\ReCaptcha($secret);
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'get':
|
||||
|
@ -2633,8 +2631,10 @@ function bb_captcha ($mode, $callback = '')
|
|||
break;
|
||||
|
||||
case 'check':
|
||||
$g_resp = request_var('g-recaptcha-response', '');
|
||||
$resp = $reCaptcha->verify($g_resp, $_SERVER['REMOTE_ADDR']);
|
||||
$resp = $di->captcha->verify(
|
||||
$di->request->get('g-recaptcha-response', ''),
|
||||
$di->request->server->get('REMOTE_ADDR')
|
||||
);
|
||||
if ($resp->isSuccess())
|
||||
{
|
||||
return true;
|
||||
|
|
19
src/ServiceProviders/CaptchaServiceProvider.php
Normal file
19
src/ServiceProviders/CaptchaServiceProvider.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace TorrentPier\ServiceProviders;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
class CaptchaServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['captcha'] = function (Container $container) {
|
||||
$captcha = new ReCaptcha($container['config.captcha.secret_key']);
|
||||
|
||||
return $captcha;
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue