mirror of
https://github.com/elyby/accounts.git
synced 2025-01-13 07:22:18 +05:30
Добавлен API вызов для получения активного Recaptcha public key
This commit is contained in:
parent
c2986445f1
commit
5e40ccbe49
@ -5,11 +5,17 @@ use yii\base\InvalidConfigException;
|
|||||||
|
|
||||||
class Component extends \yii\base\Component {
|
class Component extends \yii\base\Component {
|
||||||
|
|
||||||
|
public $public;
|
||||||
|
|
||||||
public $secret;
|
public $secret;
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
if ($this->secret === NULL) {
|
if ($this->public === null) {
|
||||||
throw new InvalidConfigException('');
|
throw new InvalidConfigException('Public is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->secret === null) {
|
||||||
|
throw new InvalidConfigException('Secret is required');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
api/controllers/OptionsController.php
Normal file
30
api/controllers/OptionsController.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
namespace api\controllers;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use yii\web\Response;
|
||||||
|
|
||||||
|
class OptionsController extends Controller {
|
||||||
|
|
||||||
|
public function behaviors() {
|
||||||
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
|
'authenticator' => [
|
||||||
|
'except' => ['recaptcha-public-key'],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verbs() {
|
||||||
|
return [
|
||||||
|
'recaptcha-public-key' => ['GET'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionRecaptchaPublicKey() {
|
||||||
|
Yii::$app->response->format = Response::FORMAT_RAW;
|
||||||
|
|
||||||
|
return Yii::$app->reCaptcha->public;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,7 @@ $config = [
|
|||||||
'cookieValidationKey' => '',
|
'cookieValidationKey' => '',
|
||||||
],
|
],
|
||||||
'reCaptcha' => [
|
'reCaptcha' => [
|
||||||
|
'public' => '',
|
||||||
'secret' => '',
|
'secret' => '',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -7,6 +7,7 @@ $config = [
|
|||||||
'cookieValidationKey' => '',
|
'cookieValidationKey' => '',
|
||||||
],
|
],
|
||||||
'reCaptcha' => [
|
'reCaptcha' => [
|
||||||
|
'public' => '',
|
||||||
'secret' => '',
|
'secret' => '',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -6,6 +6,7 @@ return [
|
|||||||
'cookieValidationKey' => '',
|
'cookieValidationKey' => '',
|
||||||
],
|
],
|
||||||
'reCaptcha' => [
|
'reCaptcha' => [
|
||||||
|
'public' => '',
|
||||||
'secret' => '',
|
'secret' => '',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
16
tests/codeception/api/_pages/OptionsRoute.php
Normal file
16
tests/codeception/api/_pages/OptionsRoute.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\api\_pages;
|
||||||
|
|
||||||
|
use yii\codeception\BasePage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property \tests\codeception\api\FunctionalTester $actor
|
||||||
|
*/
|
||||||
|
class OptionsRoute extends BasePage {
|
||||||
|
|
||||||
|
public function recaptchaPublicKey() {
|
||||||
|
$this->route = ['options/recaptcha-public-key'];
|
||||||
|
$this->actor->sendGET($this->getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
tests/codeception/api/functional/OptionsCest.php
Normal file
28
tests/codeception/api/functional/OptionsCest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace codeception\api\functional;
|
||||||
|
|
||||||
|
use tests\codeception\api\_pages\OptionsRoute;
|
||||||
|
use tests\codeception\api\FunctionalTester;
|
||||||
|
|
||||||
|
class OptionsCest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OptionsRoute
|
||||||
|
*/
|
||||||
|
private $route;
|
||||||
|
|
||||||
|
public function _before(FunctionalTester $I) {
|
||||||
|
$this->route = new OptionsRoute($I);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecaptchaPublicKey(FunctionalTester $I) {
|
||||||
|
$I->wantTo('Get recaptcha public key');
|
||||||
|
|
||||||
|
$this->route->recaptchaPublicKey();
|
||||||
|
$I->canSeeResponseCodeIs(200);
|
||||||
|
// TODO: эта проверка не проходит, т.к внутри почему-то после запроса не устанавливаются http заголовки
|
||||||
|
//$I->seeHttpHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
|
$I->canSeeResponseEquals('public-key');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user