Edit the mail config from the dashboard and provide testing button
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Commands\System\Config;
|
||||
|
||||
/**
|
||||
* This is the update config command class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class UpdateConfigCommand
|
||||
{
|
||||
/**
|
||||
* This is the config key/values array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $values;
|
||||
|
||||
/**
|
||||
* Create a new update config command instance.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Commands\System\Mail;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
|
||||
/**
|
||||
* This is the test mail command class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class TestMailCommand
|
||||
{
|
||||
/**
|
||||
* The user to send the notification to.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new test mail command.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Handlers\Commands\System\Config;
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Dotenv\Exception\InvalidPathException;
|
||||
use CachetHQ\Cachet\Bus\Commands\System\Config\UpdateConfigCommand;
|
||||
|
||||
/**
|
||||
* This is the update config command handler class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class UpdateConfigCommandHandler
|
||||
{
|
||||
/**
|
||||
* Handle update config command handler instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Bus\Commands\System\Config\UpdateConfigCommand $command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UpdateConfigCommand $command)
|
||||
{
|
||||
foreach ($command->values as $setting => $value) {
|
||||
$this->writeEnv($setting, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes to the .env file with given parameters.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function writeEnv($key, $value)
|
||||
{
|
||||
$dir = app()->environmentPath();
|
||||
$file = app()->environmentFile();
|
||||
$path = "{$dir}/{$file}";
|
||||
|
||||
try {
|
||||
(new Dotenv($dir, $file))->load();
|
||||
|
||||
$envKey = strtoupper($key);
|
||||
$envValue = env($envKey) ?: 'null';
|
||||
|
||||
file_put_contents($path, str_replace(
|
||||
"{$envKey}={$envValue}",
|
||||
"{$envKey}={$value}",
|
||||
file_get_contents($path)
|
||||
));
|
||||
} catch (InvalidPathException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Handlers\Commands\System\Mail;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Commands\System\Mail\TestMailCommand;
|
||||
use Illuminate\Contracts\Mail\MailQueue;
|
||||
|
||||
/**
|
||||
* This is the test mail command handler class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class TestMailCommandHandler
|
||||
{
|
||||
/**
|
||||
* The mailer instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Mail\Mailer
|
||||
*/
|
||||
protected $mailer;
|
||||
|
||||
/**
|
||||
* Create a test mail command handler.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailer $mailer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MailQueue $mailer)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the test mail command.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Bus\Commands\System\Mail\TestMailCommand $command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(TestMailCommand $command)
|
||||
{
|
||||
$mail = [
|
||||
'email' => $command->user->email,
|
||||
'subject' => trans('dashboard.settings.mail.email.subject'),
|
||||
];
|
||||
|
||||
$this->mailer->queue([
|
||||
'html' => 'emails.system.test-html',
|
||||
'text' => 'emails.system.test-text',
|
||||
], $mail, function ($message) use ($mail) {
|
||||
$message->to($mail['email'])->subject($mail['subject']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use CachetHQ\Cachet\Models\Schedule;
|
||||
use CachetHQ\Cachet\Models\Subscriber;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
/**
|
||||
* This is the settings composer.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class SettingsComposer
|
||||
{
|
||||
/**
|
||||
* Array of cache drivers.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $cacheDrivers = [
|
||||
'apc' => 'APC(u)',
|
||||
'array' => 'Array',
|
||||
'database' => 'Database',
|
||||
'file' => 'File',
|
||||
'memcached' => 'Memcached',
|
||||
'redis' => 'Redis',
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of cache drivers.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $mailDrivers = [
|
||||
'smtp' => 'SMTP',
|
||||
'mail' => 'Mail',
|
||||
'sendmail' => 'Sendmail',
|
||||
'mailgun' => 'Mailgun',
|
||||
'mandrill' => 'Mandrill',
|
||||
// 'ses' => 'Amazon SES', this will be available only if aws/aws-sdk-php is installed
|
||||
'sparkpost' => 'SparkPost',
|
||||
'log' => 'Log (Testing)',
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of queue drivers.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $queueDrivers = [
|
||||
'null' => 'None',
|
||||
'sync' => 'Synchronous',
|
||||
'database' => 'Database',
|
||||
'beanstalkd' => 'Beanstalk',
|
||||
'sqs' => 'Amazon SQS',
|
||||
'redis' => 'Redis',
|
||||
];
|
||||
|
||||
/**
|
||||
* Bind data to the view.
|
||||
*
|
||||
* @param \Illuminate\Contracts\View\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$view->withCacheDrivers($this->cacheDrivers);
|
||||
$view->withMailDrivers($this->mailDrivers);
|
||||
$view->withQueueDrivers($this->queueDrivers);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ use CachetHQ\Cachet\Composers\Modules\ScheduledComposer as ScheduledModuleCompos
|
||||
use CachetHQ\Cachet\Composers\Modules\StatusComposer as StatusModuleComposer;
|
||||
use CachetHQ\Cachet\Composers\Modules\StickiedComposer as StickiedModuleComposer;
|
||||
use CachetHQ\Cachet\Composers\Modules\TimelineComposer as TimelineModuleComposer;
|
||||
use CachetHQ\Cachet\Composers\SettingsComposer;
|
||||
use CachetHQ\Cachet\Composers\ThemeComposer;
|
||||
use CachetHQ\Cachet\Composers\TimezoneLocaleComposer;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
@@ -48,6 +49,7 @@ class ComposerServiceProvider extends ServiceProvider
|
||||
$factory->composer('partials.modules.scheduled', ScheduledModuleComposer::class);
|
||||
$factory->composer('partials.modules.status', StatusModuleComposer::class);
|
||||
$factory->composer('partials.modules.timeline', TimelineModuleComposer::class);
|
||||
$factory->composer(['dashboard.settings.mail', 'setup.*'], SettingsComposer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,15 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Commands\System\Config\UpdateConfigCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\System\Mail\TestMailCommand;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\Credits;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use CachetHQ\Cachet\Settings\Repository;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -96,6 +99,12 @@ class SettingsController extends Controller
|
||||
'icon' => 'ion-ios-list',
|
||||
'active' => false,
|
||||
],
|
||||
'mail' => [
|
||||
'title' => trans('dashboard.settings.mail.mail'),
|
||||
'url' => cachet_route('dashboard.settings.mail'),
|
||||
'icon' => 'ion-paper-airplane',
|
||||
'active' => false,
|
||||
],
|
||||
'about' => [
|
||||
'title' => CACHET_VERSION,
|
||||
'url' => 'javascript: void(0);',
|
||||
@@ -266,6 +275,47 @@ class SettingsController extends Controller
|
||||
return View::make('dashboard.settings.log')->withLog($logContents)->withSubMenu($this->subMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the mail settings view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMailView()
|
||||
{
|
||||
$this->subMenu['mail']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.mail')->withConfig(Config::get('mail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the mail config.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function testMail()
|
||||
{
|
||||
dispatch(new TestMailCommand(Auth::user()));
|
||||
|
||||
return cachet_redirect('dashboard.settings.mail')
|
||||
->withSuccess(trans('dashboard.notifications.awesome'));;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle updating of the settings.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postMail()
|
||||
{
|
||||
$config = Binput::get('config');
|
||||
|
||||
dispatch(new UpdateConfigCommand($config));
|
||||
|
||||
return cachet_redirect('dashboard.settings.mail')
|
||||
->withInput(Binput::all())
|
||||
->withSuccess(trans('dashboard.notifications.awesome'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status page settings.
|
||||
*
|
||||
|
||||
@@ -78,6 +78,18 @@ class SettingRoutes
|
||||
'as' => 'get:dashboard.settings.log',
|
||||
'uses' => 'SettingsController@showLogView',
|
||||
]);
|
||||
$router->get('mail', [
|
||||
'as' => 'get:dashboard.settings.mail',
|
||||
'uses' => 'SettingsController@showMailView',
|
||||
]);
|
||||
$router->post('mail', [
|
||||
'as' => 'post:dashboard.settings.mail',
|
||||
'uses' => 'SettingsController@postMail',
|
||||
]);
|
||||
$router->post('mail/test', [
|
||||
'as' => 'post:dashboard.settings.mail.test',
|
||||
'uses' => 'SettingsController@testMail',
|
||||
]);
|
||||
|
||||
$router->post('/', [
|
||||
'as' => 'post:dashboard.settings',
|
||||
|
||||
Reference in New Issue
Block a user