-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yegor Shytikov
committed
Oct 20, 2021
0 parents
commit be25bb7
Showing
134 changed files
with
9,466 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Captcha\Block\Adminhtml\Captcha; | ||
|
||
/** | ||
* Captcha block for adminhtml area | ||
*/ | ||
class DefaultCaptcha extends \Magento\Captcha\Block\Captcha\DefaultCaptcha | ||
{ | ||
/** | ||
* @var \Magento\Backend\Model\UrlInterface | ||
*/ | ||
protected $_url; | ||
|
||
/** | ||
* @var \Magento\Backend\App\ConfigInterface | ||
*/ | ||
protected $_config; | ||
|
||
/** | ||
* @param \Magento\Framework\View\Element\Template\Context $context | ||
* @param \Magento\Captcha\Helper\Data $captchaData | ||
* @param \Magento\Backend\Model\UrlInterface $url | ||
* @param \Magento\Backend\App\ConfigInterface $config | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Magento\Captcha\Helper\Data $captchaData, | ||
\Magento\Backend\Model\UrlInterface $url, | ||
\Magento\Backend\App\ConfigInterface $config, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $captchaData, $data); | ||
$this->_url = $url; | ||
$this->_config = $config; | ||
} | ||
|
||
/** | ||
* Returns URL to controller action which returns new captcha image | ||
* | ||
* @return string | ||
*/ | ||
public function getRefreshUrl() | ||
{ | ||
return $this->_url->getUrl( | ||
'adminhtml/refresh/refresh', | ||
['_secure' => $this->_config->isSetFlag('web/secure/use_in_adminhtml'), '_nosecret' => true] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* Captcha block | ||
* | ||
* @author Magento Core Team <core@magentocommerce.com> | ||
*/ | ||
namespace Magento\Captcha\Block; | ||
|
||
/** | ||
* @api | ||
* @since 100.0.2 | ||
*/ | ||
class Captcha extends \Magento\Framework\View\Element\Template | ||
{ | ||
/** | ||
* Captcha data | ||
* | ||
* @var \Magento\Captcha\Helper\Data | ||
*/ | ||
protected $_captchaData = null; | ||
|
||
/** | ||
* @param \Magento\Framework\View\Element\Template\Context $context | ||
* @param \Magento\Captcha\Helper\Data $captchaData | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Magento\Captcha\Helper\Data $captchaData, | ||
array $data = [] | ||
) { | ||
$this->_captchaData = $captchaData; | ||
parent::__construct($context, $data); | ||
$this->_isScopePrivate = true; | ||
} | ||
|
||
/** | ||
* Renders captcha HTML (if required) | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
$blockPath = $this->_captchaData->getCaptcha($this->getFormId())->getBlockName(); | ||
$block = $this->getLayout()->createBlock($blockPath); | ||
$block->setData($this->getData()); | ||
return $block->toHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Captcha\Block\Captcha; | ||
|
||
/** | ||
* Captcha block | ||
*/ | ||
class DefaultCaptcha extends \Magento\Framework\View\Element\Template | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $_template = 'Magento_Captcha::default.phtml'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_captcha; | ||
|
||
/** | ||
* @var \Magento\Captcha\Helper\Data | ||
*/ | ||
protected $_captchaData; | ||
|
||
/** | ||
* @param \Magento\Framework\View\Element\Template\Context $context | ||
* @param \Magento\Captcha\Helper\Data $captchaData | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Magento\Captcha\Helper\Data $captchaData, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->_captchaData = $captchaData; | ||
} | ||
|
||
/** | ||
* Returns template path | ||
* | ||
* @return string | ||
*/ | ||
public function getTemplate() | ||
{ | ||
return $this->getIsAjax() ? '' : $this->_template; | ||
} | ||
|
||
/** | ||
* Returns URL to controller action which returns new captcha image | ||
* | ||
* @return string | ||
*/ | ||
public function getRefreshUrl() | ||
{ | ||
$store = $this->_storeManager->getStore(); | ||
return $store->getUrl('captcha/refresh', ['_secure' => $store->isCurrentlySecure()]); | ||
} | ||
|
||
/** | ||
* Renders captcha HTML (if required) | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if ($this->getCaptchaModel()->isRequired()) { | ||
$this->getCaptchaModel()->generate(); | ||
return parent::_toHtml(); | ||
} | ||
return ''; | ||
} | ||
|
||
/** | ||
* Returns captcha model | ||
* | ||
* @return \Magento\Captcha\Model\CaptchaInterface | ||
*/ | ||
public function getCaptchaModel() | ||
{ | ||
return $this->_captchaData->getCaptcha($this->getFormId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Refreshes captcha and returns JSON encoded URL to image (AJAX action) | ||
* Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'} | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Captcha\Controller\Adminhtml\Refresh; | ||
|
||
class Refresh extends \Magento\Backend\App\Action | ||
{ | ||
/** | ||
* @var \Magento\Framework\Serialize\Serializer\Json | ||
*/ | ||
protected $serializer; | ||
|
||
/** | ||
* @var \Magento\Captcha\Helper\Data | ||
*/ | ||
protected $captchaHelper; | ||
|
||
/** | ||
* Refresh constructor. | ||
* @param \Magento\Backend\App\Action\Context $context | ||
* @param \Magento\Captcha\Helper\Data $captchaHelper | ||
* @param \Magento\Framework\Serialize\Serializer\Json $serializer | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Captcha\Helper\Data $captchaHelper, | ||
\Magento\Framework\Serialize\Serializer\Json $serializer | ||
) { | ||
parent::__construct($context); | ||
$this->serializer = $serializer; | ||
$this->captchaHelper = $captchaHelper; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute() | ||
{ | ||
$formId = $this->getRequest()->getPost('formId'); | ||
$captchaModel = $this->captchaHelper->getCaptcha($formId); | ||
$this->_view->getLayout()->createBlock( | ||
$captchaModel->getBlockName() | ||
)->setFormId( | ||
$formId | ||
)->setIsAjax( | ||
true | ||
)->toHtml(); | ||
$this->getResponse()->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()])); | ||
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true); | ||
} | ||
|
||
/** | ||
* Check if user has permissions to access this controller | ||
* | ||
* @return bool | ||
*/ | ||
protected function _isAllowed() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Captcha\Controller\Refresh; | ||
|
||
use Magento\Captcha\Helper\Data as CaptchaHelper; | ||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\JsonFactory as JsonResultFactory; | ||
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; | ||
use Magento\Framework\View\LayoutInterface; | ||
|
||
/** | ||
* Refreshes captcha and returns JSON encoded URL to image (AJAX action) | ||
* Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'} | ||
*/ | ||
class Index extends Action implements HttpPostActionInterface | ||
{ | ||
/** | ||
* @var CaptchaHelper | ||
*/ | ||
private $captchaHelper; | ||
|
||
/** | ||
* @var JsonSerializer | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var LayoutInterface | ||
*/ | ||
private $layout; | ||
|
||
/** | ||
* @var JsonResultFactory | ||
*/ | ||
private $jsonResultFactory; | ||
|
||
/** | ||
* @param Context $context | ||
* @param RequestInterface $request | ||
* @param JsonResultFactory $jsonFactory | ||
* @param CaptchaHelper $captchaHelper | ||
* @param LayoutInterface $layout | ||
* @param JsonSerializer $serializer | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
RequestInterface $request, | ||
JsonResultFactory $jsonFactory, | ||
CaptchaHelper $captchaHelper, | ||
LayoutInterface $layout, | ||
JsonSerializer $serializer | ||
) { | ||
parent::__construct($context); | ||
$this->request = $request; | ||
$this->jsonResultFactory = $jsonFactory; | ||
$this->captchaHelper = $captchaHelper; | ||
$this->layout = $layout; | ||
$this->serializer = $serializer; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
$formId = $this->getRequestFormId(); | ||
|
||
$captchaModel = $this->captchaHelper->getCaptcha($formId); | ||
$captchaModel->generate(); | ||
|
||
$block = $this->layout->createBlock($captchaModel->getBlockName()); | ||
$block->setFormId($formId)->setIsAjax(true)->toHtml(); | ||
|
||
$result = $this->jsonResultFactory->create(); | ||
|
||
return $result->setData(['imgSrc' => $captchaModel->getImgSrc()]); | ||
} | ||
|
||
/** | ||
* Returns requested Form ID | ||
* | ||
* @return string|null | ||
*/ | ||
private function getRequestFormId(): ?string | ||
{ | ||
$formId = $this->request->getPost('formId'); | ||
if (null === $formId) { | ||
$params = []; | ||
$content = $this->request->getContent(); | ||
if ($content) { | ||
$params = $this->serializer->unserialize($content); | ||
} | ||
|
||
$formId = $params['formId'] ?? null; | ||
} | ||
|
||
return $formId !== null ? (string)$formId : null; | ||
} | ||
} |
Oops, something went wrong.