Skip to content

Commit

Permalink
Decrypt the information when editing setting.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 12, 2016
1 parent 10aa11e commit 450f99e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/Http/Presenters/Setting.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
<?php namespace Orchestra\Foundation\Http\Presenters;

use Orchestra\Contracts\Html\Form\Fieldset;
use Illuminate\Contracts\Encryption\Encrypter;
use Orchestra\Contracts\Html\Form\Grid as FormGrid;
use Orchestra\Contracts\Html\Form\Factory as FormFactory;

class Setting extends Presenter
{
/**
* The encrypter implementation.
*
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
protected $encrypter;

/**
* Construct a new User presenter.
*
* @param \Orchestra\Contracts\Html\Form\Factory $form
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(FormFactory $form)
public function __construct(FormFactory $form, Encrypter $encrypter)
{
$this->form = $form;
$this->encrypter = $encrypter;
}

/**
Expand Down Expand Up @@ -70,7 +80,9 @@ protected function application(FormGrid $form)
*/
protected function mailer(FormGrid $form, $model)
{
$form->fieldset(trans('orchestra/foundation::label.settings.mail'), function (Fieldset $fieldset) use ($model) {
$encrypter = $this->encrypter;

$form->fieldset(trans('orchestra/foundation::label.settings.mail'), function (Fieldset $fieldset) use ($encrypter, $model) {
$fieldset->control('select', 'email_driver')
->label(trans('orchestra/foundation::label.email.driver'))
->options([
Expand Down Expand Up @@ -106,10 +118,16 @@ protected function mailer(FormGrid $form, $model)
->label(trans('orchestra/foundation::label.email.encryption'));

$fieldset->control('input:text', 'email_key')
->label(trans('orchestra/foundation::label.email.key'));
->label(trans('orchestra/foundation::label.email.key'))
->value(function ($row) use ($encrypter) {
return $encrypter->decrypt($row->email_key);
});

$fieldset->control('input:password', 'email_secret')
->label(trans('orchestra/foundation::label.email.secret'))
->value(function ($row) use ($encrypter) {
return $encrypter->decrypt($row->email_secret);
})
->help(view('orchestra/foundation::settings._hidden', [
'model' => $model,
'action' => 'change_secret',
Expand Down
4 changes: 3 additions & 1 deletion tests/Foundation/Http/Presenters/SettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function testFormMethod()
$app['Illuminate\Contracts\View\Factory'] = m::mock('\Illuminate\Contracts\View\Factory');

$form = m::mock('\Orchestra\Contracts\Html\Form\Factory');
$encrypter = m::mock('\Illuminate\Contracts\Encryption\Encrypter');
$grid = m::mock('\Orchestra\Contracts\Html\Form\Grid');

$siteFieldset = m::mock('\Orchestra\Contracts\Html\Form\Fieldset');
Expand All @@ -66,7 +67,7 @@ public function testFormMethod()
$emailFieldset = m::mock('\Orchestra\Contracts\Html\Form\Fieldset');
$emailControl = m::mock('\Orchestra\Contracts\Html\Form\Control');

$stub = new Setting($form);
$stub = new Setting($form, $encrypter);

$siteFieldset->shouldReceive('control')->times(3)->andReturn($siteControl);
$siteControl->shouldReceive('label')->times(3)->andReturnSelf()
Expand All @@ -78,6 +79,7 @@ public function testFormMethod()
$emailControl->shouldReceive('label')->times(13)->andReturnSelf()
->shouldReceive('attributes')->once()->andReturnSelf()
->shouldReceive('options')->times(3)->andReturnSelf()
->shouldReceive('value')->times(2)->andReturnSelf()
->shouldReceive('help')->twice()->with('email.password.help');

$grid->shouldReceive('setup')->once()
Expand Down

0 comments on commit 450f99e

Please sign in to comment.