Skip to content

Commit

Permalink
Add support for CAPTCHA
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiphan committed Jun 10, 2018
1 parent dc3f9a8 commit b8b1e1c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Model/Captcha/DefaultModel/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace Thai\S3\Model\Captcha\DefaultModel;

use Thai\S3\Helper\Data;
use Magento\Cms\Model\Wysiwyg\Images\Storage;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\MediaStorage\Helper\File\Storage\Database;

class Plugin
{
private $helper;
private $database;

public function __construct(
Data $helper,
Database $database
) {
$this->helper = $helper;
$this->database = $database;
}

public function afterGenerate(\Magento\Captcha\Model\DefaultModel $subject, $result)
{
if ($this->helper->checkS3Usage()) {
$imgFile = $subject->getImgDir() . $result . $subject->getSuffix();
$relativeImgFile = $this->database->getMediaRelativePath($imgFile);
$this->database->getStorageDatabaseModel()->saveFile($relativeImgFile);
}

return $result;
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following images are automatically saved to S3:
* Generated thumbnails
* WYSIWYG images
* Category images
* CAPTCHA images

### Magento can now scale horizontally

Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@
<type name="Magento\Swatches\Helper\Media">
<plugin name="thai_s3_helper_swatches_media_plugin" type="Thai\S3\Helper\Swatches\Media\Plugin" />
</type>
<type name="Magento\Captcha\Model\DefaultModel">
<plugin name="thai_s3_model_captcha_defaultmodel_plugin" type="Thai\S3\Model\Captcha\DefaultModel\Plugin" />
</type>
</config>

0 comments on commit b8b1e1c

Please sign in to comment.