Files
magento2/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Save.php
T
Cari Spruiell 2072220101 MAGETWO-38570: Refactor as much functionality from PCI module to rest of core/library modules
- moved admin user password and locking functionality from PasswordManagement to User module
 - moved customer password upgrade from PasswordManagement to Customer module
 - renamed PasswordManagement module to EncryptionKey to contain the encryption key management code
2015-08-27 15:34:05 -05:00

86 lines
2.5 KiB
PHP

<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key;
/**
* Encryption Key Save Controller
*/
class Save extends \Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key
{
/**
* @var \Magento\Framework\Encryption\EncryptorInterface
*/
protected $encryptor;
/**
* @var \Magento\EncryptionKey\Model\Resource\Key\Change
*/
protected $change;
/**
* @var \Magento\Framework\App\CacheInterface
*/
protected $cache;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Magento\EncryptionKey\Model\Resource\Key\Change $change
* @param \Magento\Framework\App\CacheInterface $cache
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\EncryptionKey\Model\Resource\Key\Change $change,
\Magento\Framework\App\CacheInterface $cache
) {
$this->encryptor = $encryptor;
$this->change = $change;
$this->cache = $cache;
parent::__construct($context);
}
/**
* Process saving new encryption key
*
* @return void
*/
public function execute()
{
try {
$key = null;
if (0 == $this->getRequest()->getPost('generate_random')) {
$key = $this->getRequest()->getPost('crypt_key');
if (empty($key)) {
throw new \Exception(__('Please enter an encryption key.'));
}
$this->encryptor->validateKey($key);
}
$newKey = $this->change->changeEncryptionKey($key);
$this->messageManager->addSuccess(__('The encryption key has been changed.'));
if (!$key) {
$this->messageManager->addNotice(
__(
'This is your new encryption key: <span style="font-family:monospace;">%1</span>. ' .
'Be sure to write it down and take good care of it!',
$newKey
)
);
}
$this->cache->clean();
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->_session->setFormData(['crypt_key' => $key]);
}
$this->_redirect('adminhtml/*/');
}
}