Skip to content

Commit

Permalink
Encrypt private value.
Browse files Browse the repository at this point in the history
Solved #206

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 12, 2016
1 parent 0582834 commit 10aa11e
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/Processor/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Illuminate\Support\Facades\Config;
use Orchestra\Contracts\Memory\Provider;
use Orchestra\Support\Facades\Foundation;
use Illuminate\Contracts\Encryption\Encrypter;
use Orchestra\Foundation\Validation\Setting as Validator;
use Orchestra\Foundation\Http\Presenters\Setting as Presenter;
use Orchestra\Contracts\Foundation\Command\SystemUpdater as SystemUpdateCommand;
use Orchestra\Contracts\Foundation\Listener\SystemUpdater as SystemUpdateListener;
use Orchestra\Contracts\Foundation\Command\SettingUpdater as SettingUpdateCommand;
use Orchestra\Contracts\Foundation\Listener\SystemUpdater as SystemUpdateListener;
use Orchestra\Contracts\Foundation\Listener\SettingUpdater as SettingUpdateListener;

class Setting extends Processor implements SystemUpdateCommand, SettingUpdateCommand
Expand All @@ -21,18 +22,27 @@ class Setting extends Processor implements SystemUpdateCommand, SettingUpdateCom
*/
protected $memory;

/**
* The encrypter implementation.
*
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
protected $encrypter;

/**
* Create a new processor instance.
*
* @param \Orchestra\Foundation\Http\Presenters\Setting $presenter
* @param \Orchestra\Foundation\Validation\Setting $validator
* @param \Orchestra\Contracts\Memory\Provider $memory
* @param \\Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(Presenter $presenter, Validator $validator, Provider $memory)
public function __construct(Presenter $presenter, Validator $validator, Provider $memory, Encrypter $encrypter)
{
$this->presenter = $presenter;
$this->validator = $validator;
$this->memory = $memory;
$this->encrypter = $encrypter;
}

/**
Expand Down Expand Up @@ -117,12 +127,12 @@ public function update(SettingUpdateListener $listener, array $input)
$memory->put('email.host', $this->getValue($input['email_host'], 'mail.host'));
$memory->put('email.port', $this->getValue($input['email_port'], 'mail.port'));
$memory->put('email.username', $this->getValue($input['email_username'], 'mail.username'));
$memory->put('email.password', $this->getValue($input['email_password'], 'mail.password'));
$memory->put('email.password', $this->getEncryptedValue($input['email_password'], 'mail.password'));
$memory->put('email.encryption', $this->getValue($input['email_encryption'], 'mail.encryption'));
$memory->put('email.sendmail', $this->getValue($input['email_sendmail'], 'mail.sendmail'));
$memory->put('email.queue', ($input['email_queue'] === 'yes'));
$memory->put('email.key', $this->getValue($input['email_key'], "services.{$driver}.key"));
$memory->put('email.secret', $this->getValue($input['email_secret'], "services.{$driver}.secret"));
$memory->put('email.key', $this->getEncryptedValue($input['email_key'], "services.{$driver}.key"));
$memory->put('email.secret', $this->getEncryptedValue($input['email_secret'], "services.{$driver}.secret"));
$memory->put('email.domain', $this->getValue($input['email_domain'], "services.{$driver}.domain"));
$memory->put('email.region', $this->getValue($input['email_region'], "services.{$driver}.region"));

Expand Down Expand Up @@ -162,4 +172,19 @@ private function getValue($input, $alternative)

return $input;
}

/**
* Resolve value or grab from configuration.
*
* @param mixed $input
* @param string $alternative
*
* @return mixed
*/
private function getEncryptedValue($input, $alternative)
{
$value = $this->getValue($input, $alternative);

return $this->encrypter->encrypt($value);
}
}

0 comments on commit 10aa11e

Please sign in to comment.