Skip to content

Commit

Permalink
Add support to edit e-mail settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmy committed Mar 6, 2016
1 parent 2732e39 commit ae5c7eb
Show file tree
Hide file tree
Showing 29 changed files with 1,404 additions and 21 deletions.
7 changes: 7 additions & 0 deletions app/Entities/Setting/AbstractSettingEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace App\Entities\Setting;

abstract class AbstractSettingEntity
{
}
120 changes: 120 additions & 0 deletions app/Entities/Setting/MailSettingEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace App\Entities\Setting;

use App\Entities\Setting\AbstractSettingEntity;

class MailSettingEntity extends AbstractSettingEntity
{
protected $driver;

protected $from;

protected $smtpHost;

protected $smtpPort;

protected $smtpEncryption;

protected $smtpUsername;

protected $smtpPassword;

protected $sendmailPath;

public function getDriver()
{
return $this->driver;
}

public function getFrom()
{
return $this->from;
}

public function getSmtpHost()
{
return $this->smtpHost;
}

public function getSmtpPort()
{
return $this->smtpPort;
}

public function getSmtpEncryption()
{
return $this->smtpEncryption;
}

public function getSmtpUsername()
{
return $this->smtpUsername;
}

public function getSmtpPassword()
{
return $this->smtpPassword;
}

public function getSendmailPath()
{
return $this->sendmailPath;
}

public function setDriver($driver)
{
$this->driver = $driver;

return $this;
}

public function setFrom(array $from)
{
$this->from = $from;

return $this;
}

public function setSmtpHost($smtpHost)
{
$this->smtpHost = $smtpHost;

return $this;
}

public function setSmtpPort($smtpPort)
{
$this->smtpPort = $smtpPort;

return $this;
}

public function setSmtpEncryption($smtpEncryption)
{
$this->smtpEncryption = $smtpEncryption;

return $this;
}

public function setSmtpUsername($smtpUsername)
{
$this->smtpUsername = $smtpUsername;

return $this;
}

public function setSmtpPassword($smtpPassword)
{
$this->smtpPassword = $smtpPassword;

return $this;
}

public function setSendmailPath($sendmailPath)
{
$this->sendmailPath = $sendmailPath;

return $this;
}
}
40 changes: 40 additions & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Services\Form\Setting\MailSettingForm;
use App\Repositories\Setting\MailSettingInterface;

class SettingsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('acl');
}

public function getEmail(MailSettingInterface $mailSettingRepository)
{
$settings = $mailSettingRepository->all();

return view('settings.email')
->with('settings', $settings);
}

public function postEmail(Request $request, MailSettingForm $mailSettingForm)
{
$input = $request->all();

if ($mailSettingForm->update($input)) {
return redirect()->route('settings.email');
} else {
return redirect()->route('settings.email')
->withInput()
->withErrors($mailSettingForm->errors());
}
}
}
8 changes: 8 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@
]);
Route::resource('users', 'UsersController');
});

Route::group([
'protect_alias' => 'setting'
], function () {
Route::controller('settings', 'SettingsController', [
'getEmail' => 'settings.email'
]);
});
24 changes: 19 additions & 5 deletions app/Jobs/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Jobs\Job;
use App\Repositories\Project\ProjectInterface;
use App\Repositories\Server\ServerInterface;
use App\Repositories\Setting\MailSettingInterface;
use App\Services\Notification\NotifierInterface;

use Illuminate\Queue\SerializesModels;
Expand Down Expand Up @@ -38,13 +39,14 @@ public function __construct(Model $deployment)
/**
* Execute the job.
*
* @param \App\Repositories\Project\ProjectInterface $projectRepository
* @param \App\Repositories\Server\ServerInterface $serverRepository
* @param \Symfony\Component\Process\ProcessBuilder $processBuilder
* @param \App\Services\Notification\NotifierInterface $notifier
* @param \App\Repositories\Project\ProjectInterface $projectRepository
* @param \App\Repositories\Server\ServerInterface $serverRepository
* @param \Symfony\Component\Process\ProcessBuilder $processBuilder
* @param \App\Services\Notification\NotifierInterface $notifier
* @param \App\Repositories\Setting\MailSettingInterface $mailSettingRepository
* @return void
*/
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier)
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier, MailSettingInterface $mailSettingRepository)
{
$deployment = $this->deployment;
$project = $projectRepository->byId($deployment->project_id);
Expand Down Expand Up @@ -105,6 +107,18 @@ public function handle(ProjectInterface $projectRepository, ServerInterface $ser

// Notify
if (isset($project->email_notification_recipient)) {
$mailSettings = $mailSettingRepository->all();

config(['mail.driver' => $mailSettings->getDriver()]);
config(['mail.from.address' => $mailSettings->getFrom()['address']]);
config(['mail.from.name' => $mailSettings->getFrom()['name']]);
config(['mail.host' => $mailSettings->getSmtpHost()]);
config(['mail.port' => $mailSettings->getSmtpPort()]);
config(['mail.encryption' => $mailSettings->getSmtpEncryption()]);
config(['mail.username' => $mailSettings->getSmtpUsername()]);
config(['mail.password' => $mailSettings->getSmtpPassword()]);
config(['mail.sendmail' => $mailSettings->getSendmailPath()]);

$deployment = $project->getDeploymentByNumber($deployment->number);

if ($process->isSuccessful()) {
Expand Down
24 changes: 19 additions & 5 deletions app/Jobs/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Jobs\Job;
use App\Repositories\Project\ProjectInterface;
use App\Repositories\Server\ServerInterface;
use App\Repositories\Setting\MailSettingInterface;
use App\Services\Notification\NotifierInterface;

use Illuminate\Queue\SerializesModels;
Expand Down Expand Up @@ -38,13 +39,14 @@ public function __construct(Model $deployment)
/**
* Execute the job.
*
* @param \App\Repositories\Project\ProjectInterface $projectRepository
* @param \App\Repositories\Server\ServerInterface $serverRepository
* @param \Symfony\Component\Process\ProcessBuilder $processBuilder
* @param \App\Services\Notification\NotifierInterface $notifier
* @param \App\Repositories\Project\ProjectInterface $projectRepository
* @param \App\Repositories\Server\ServerInterface $serverRepository
* @param \Symfony\Component\Process\ProcessBuilder $processBuilder
* @param \App\Services\Notification\NotifierInterface $notifier
* @param \App\Repositories\Setting\MailSettingInterface $mailSettingRepository
* @return void
*/
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier)
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier, MailSettingInterface $mailSettingRepository)
{
$deployment = $this->deployment;
$project = $projectRepository->byId($deployment->project_id);
Expand Down Expand Up @@ -105,6 +107,18 @@ public function handle(ProjectInterface $projectRepository, ServerInterface $ser

// Notify
if (isset($project->email_notification_recipient)) {
$mailSettings = $mailSettingRepository->all();

config(['mail.driver' => $mailSettings->getDriver()]);
config(['mail.from.address' => $mailSettings->getFrom()['address']]);
config(['mail.from.name' => $mailSettings->getFrom()['name']]);
config(['mail.host' => $mailSettings->getSmtpHost()]);
config(['mail.port' => $mailSettings->getSmtpPort()]);
config(['mail.encryption' => $mailSettings->getSmtpEncryption()]);
config(['mail.username' => $mailSettings->getSmtpUsername()]);
config(['mail.password' => $mailSettings->getSmtpPassword()]);
config(['mail.sendmail' => $mailSettings->getSendmailPath()]);

$deployment = $project->getDeploymentByNumber($deployment->number);

if ($process->isSuccessful()) {
Expand Down
19 changes: 19 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
use App\Services\Form\Server\ServerFormLaravelValidator;
use App\Services\Form\User\UserForm;
use App\Services\Form\User\UserFormLaravelValidator;
use App\Services\Form\Setting\MailSettingForm;
use App\Services\Form\Setting\MailSettingFormLaravelValidator;
use App\Services\Notification\MailNotifier;
use App\Services\Config\DotenvReader;
use App\Services\Config\DotenvWriter;
use App\Services\Filesystem\LaravelFilesystem;

Expand Down Expand Up @@ -90,10 +93,26 @@ public function register()
);
});

$this->app->bind('App\Services\Form\Setting\MailSettingForm', function ($app) {
return new MailSettingForm(
new MailSettingFormLaravelValidator($app['validator']),
$app->make('App\Repositories\Setting\MailSettingInterface')
);
});

$this->app->bind('App\Services\Notification\NotifierInterface', function ($app) {
return new MailNotifier;
});

$this->app->bind('App\Services\Config\ConfigReaderInterface', function ($app) {
$path = base_path('.env');

return new DotenvReader(
new LaravelFilesystem($app['files']),
$path
);
});

$this->app->bind('App\Services\Config\ConfigWriterInterface', function ($app) {
$path = base_path('.env');

Expand Down
8 changes: 8 additions & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Repositories\Server\EloquentServer;
use App\Repositories\User\EloquentUser;
use App\Repositories\Role\EloquentRole;
use App\Repositories\Setting\ConfigMailSetting;

use Kodeine\Acl\Models\Eloquent\Role;

Expand Down Expand Up @@ -54,5 +55,12 @@ public function register()
$this->app->bind('App\Repositories\Role\RoleInterface', function ($app) {
return new EloquentRole(new Role);
});

$this->app->bind('App\Repositories\Setting\MailSettingInterface', function ($app) {
return new ConfigMailSetting(
$app->make('App\Services\Config\ConfigReaderInterface'),
$app->make('App\Services\Config\ConfigWriterInterface')
);
});
}
}
50 changes: 50 additions & 0 deletions app/Repositories/AbstractConfigRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Repositories;

use App\Services\Config\ConfigReaderInterface;
use App\Services\Config\ConfigWriterInterface;

abstract class AbstractConfigRepository implements RepositoryInterface
{
protected $reader;

protected $writer;

/**
* Create a new repository instance.
*
* @param \App\Services\Config\ConfigReaderInterface $reader
* @param \App\Services\Config\ConfigWriterInterface $writer
* @return void
*/
public function __construct(ConfigReaderInterface $reader, ConfigWriterInterface $writer)
{
$this->reader = $reader;
$this->writer = $writer;
}

public function byId($id)
{
}

public function byPage($page = 1, $limi = 10)
{
}

public function all()
{
}

public function create(array $data)
{
}

public function update(array $data)
{
}

public function delete($id)
{
}
}

0 comments on commit ae5c7eb

Please sign in to comment.