Merge pull request #702 from cachethq/subscriber-config

Closes #700 - Subscribers can now be turned on and off
This commit is contained in:
James Brooks
2015-06-10 22:13:04 +01:00
8 changed files with 119 additions and 66 deletions

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* 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\Facades\Setting;
use Illuminate\Contracts\View\View;
class AppComposer
{
/**
* Index page view composer.
*
* @param \Illuminate\Contracts\View\View $view
*/
public function compose(View $view)
{
$isEnabled = (bool) Setting::get('enable_subscribers', false);
$mailAddress = env('MAIL_ADDRESS', false);
$mailFrom = env('MAIL_NAME', false);
$withData = [
'subscribersEnabled' => $isEnabled && $mailAddress && $mailFrom,
];
$view->with($withData);
}
}

View File

@@ -35,14 +35,15 @@ class Kernel extends HttpKernel
* @var array
*/
protected $routeMiddleware = [
'auth' => 'CachetHQ\Cachet\Http\Middleware\Authenticate',
'auth.api' => 'CachetHQ\Cachet\Http\Middleware\ApiAuthenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated',
'csrf' => 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
'admin' => 'CachetHQ\Cachet\Http\Middleware\Admin',
'login.throttling' => 'CachetHQ\Cachet\Http\Middleware\LoginThrottling',
'app.isSetup' => 'CachetHQ\Cachet\Http\Middleware\AppIsSetup',
'app.hasSetting' => 'CachetHQ\Cachet\Http\Middleware\HasSetting',
'auth' => 'CachetHQ\Cachet\Http\Middleware\Authenticate',
'auth.api' => 'CachetHQ\Cachet\Http\Middleware\ApiAuthenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated',
'csrf' => 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
'admin' => 'CachetHQ\Cachet\Http\Middleware\Admin',
'login.throttling' => 'CachetHQ\Cachet\Http\Middleware\LoginThrottling',
'app.isSetup' => 'CachetHQ\Cachet\Http\Middleware\AppIsSetup',
'app.hasSetting' => 'CachetHQ\Cachet\Http\Middleware\HasSetting',
'app.subscribers' => 'CachetHQ\Cachet\Http\Middleware\SubscribersConfigured',
];
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Http\Middleware;
use CachetHQ\Cachet\Facades\Setting;
use Closure;
use Illuminate\Support\Facades\Redirect;
class SubscribersConfigured
{
/**
* We're verifying that subscribers is both enabled and configured.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
$isEnabled = Setting::get('enable_subscribers', false);
$mailAddress = env('MAIL_ADDRESS', false);
$mailFrom = env('MAIL_NAME', false);
if (!($isEnabled && $mailAddress && $mailFrom)) {
return Redirect::route('status-page');
}
return $next($request);
}
}

View File

@@ -28,24 +28,28 @@ class StatusPageRoutes
'as' => 'status-page',
'uses' => 'HomeController@showIndex',
]);
$router->get('subscribe', [
'as' => 'subscribe-page',
'uses' => 'SubscribeController@showSubscribe',
]);
$router->post('subscribe', [
'as' => 'subscribe',
'uses' => 'SubscribeController@postSubscribe',
]);
$router->get('subscribe/verify/{code}', [
'as' => 'subscribe-verify',
'uses' => 'SubscribeController@getVerify',
]);
$router->get('unsubscribe/{code}', [
'as' => 'unsubscribe',
'uses' => 'SubscribeController@getUnsubscribe',
]);
$router->get('/atom/{component_group?}', 'AtomController@feedAction');
$router->get('/rss/{component_group?}', 'RssController@feedAction');
$router->group(['middleware' => 'app.subscribers'], function ($router) {
$router->get('subscribe', [
'as' => 'subscribe-page',
'uses' => 'SubscribeController@showSubscribe',
]);
$router->post('subscribe', [
'as' => 'subscribe',
'uses' => 'SubscribeController@postSubscribe',
]);
$router->get('subscribe/verify/{code}', [
'as' => 'subscribe-verify',
'uses' => 'SubscribeController@getVerify',
]);
$router->get('unsubscribe/{code}', [
'as' => 'unsubscribe',
'uses' => 'SubscribeController@getUnsubscribe',
]);
});
});
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Providers;
use CachetHQ\Cachet\Composers\AppComposer;
use CachetHQ\Cachet\Composers\DashboardComposer;
use CachetHQ\Cachet\Composers\IndexComposer;
use CachetHQ\Cachet\Composers\LoggedUserComposer;
@@ -27,6 +28,7 @@ class ComposerServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->view->composer('*', AppComposer::class);
$this->app->view->composer('*', LoggedUserComposer::class);
$this->app->view->composer(['index', 'subscribe'], IndexComposer::class);
$this->app->view->composer(['index', 'subscribe'], ThemeComposer::class);

View File

@@ -1,41 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Providers;
use Illuminate\Support\ServiceProvider;
class ViewComposerServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*/
public function boot()
{
//
}
/**
* Register the service provider.
*/
public function register()
{
$this->app->view->composer('*', 'CachetHQ\Cachet\Composers\LoggedUserComposer');
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\IndexComposer');
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\ThemeComposer');
$this->app->view->composer('subscribe', 'CachetHQ\Cachet\Composers\ThemeComposer');
$this->app->view->composer('dashboard.*', 'CachetHQ\Cachet\Composers\DashboardComposer');
$this->app->view->composer([
'setup',
'dashboard.settings.app-setup',
], 'CachetHQ\Cachet\Composers\TimezoneLocaleComposer');
}
}

View File

@@ -123,6 +123,15 @@
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label>{{ trans('forms.settings.app-setup.subscribers') }}</label>
<input type="hidden" value="0" name="enable_subscribers">
<input type="checkbox" value="1" name="enable_subscribers" class="form-control" {{ Setting::get('enable_subscribers') ? 'checked' : null }}>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group">

View File

@@ -1,9 +1,11 @@
@extends('layout.master')
@section('content')
@if($subscribersEnabled)
<div class="pull-right">
<p><a class="btn btn-success btn-outline" href="{{ route('subscribe') }}">{{ trans('cachet.subscriber.button') }}</a></p>
</div>
@endif
<div class="clearfix"></div>