Welcome all users to their status page

This commit is contained in:
James Brooks
2016-08-23 13:09:47 +01:00
parent 1b96420fc9
commit 6685ae96d8
13 changed files with 312 additions and 25 deletions
@@ -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\User;
use CachetHQ\Cachet\Models\User;
/**
* This is the welcome user command.
*
* @author James Brooks <james@alt-three.com>
*/
final class WelcomeUserCommand
{
/**
* The user.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new welcome user command instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}
@@ -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\Events\User;
use CachetHQ\Cachet\Models\User;
/**
* This is the user was welcomed event.
*
* @author James Brooks <james@alt-three.com>
*/
final class UserWasWelcomedEvent implements UserEventInterface
{
/**
* The user.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user was welcomed event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}
@@ -0,0 +1,37 @@
<?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\User;
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
use CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent;
/**
* This is the welcome user command handler.
*
* @author James Brooks <james@alt-three.com>
*/
class WelcomeUserCommandHandler
{
/**
* Handle the welcome user command.
*
* @param \CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand $command
*
* @return void
*/
public function handle(WelcomeUserCommand $command)
{
$command->user->update(['welcomed' => true]);
event(new UserWasWelcomedEvent($command->user));
}
}
@@ -138,5 +138,8 @@ class EventServiceProvider extends ServiceProvider
'CachetHQ\Cachet\Bus\Events\User\UserWasRemovedEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent' => [
//
],
];
}
@@ -11,17 +11,24 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
use CachetHQ\Cachet\Integrations\Contracts\Feed;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Subscriber;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
/**
* This is the dashboard controller class.
*
* @author James Brooks <james@alt-three.com>
*/
class DashboardController extends Controller
{
/**
@@ -83,6 +90,11 @@ class DashboardController extends Controller
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
$ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
$welcomeUser = !Auth::user()->welcomed;
if ($welcomeUser) {
dispatch(new WelcomeUserCommand(Auth::user()));
}
$entries = null;
if ($feed = $this->feed->latest()) {
$entries = array_slice($feed->channel->item, 0, 5);
@@ -95,7 +107,8 @@ class DashboardController extends Controller
->withSubscribers($subscribers)
->withEntries($entries)
->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents);
->withUngroupedComponents($ungroupedComponents)
->withWelcomeUser($welcomeUser);
}
/**
-3
View File
@@ -22,7 +22,6 @@ use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
@@ -217,8 +216,6 @@ class SetupController extends Controller
$this->writeEnv($envKey, $envValue);
}
Session::flash('setup.done', true);
if (Request::ajax()) {
return Response::json(['status' => 1]);
}
+31
View File
@@ -21,6 +21,11 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Hash;
/**
* This is the user model.
*
* @author James Brooks <james@alt-three.com>
*/
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, ValidatingTrait;
@@ -39,6 +44,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/
const LEVEL_USER = 2;
/**
* The model's attributes.
*
* @var string[]
*/
protected $attributes = [
'welcomed' => false,
];
/**
* The attributes that should be casted to native types.
*
@@ -51,6 +65,23 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
'api_key' => 'string',
'active' => 'bool',
'level' => 'int',
'welcomed' => 'bool',
];
/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = [
'username',
'password',
'google_2fa_secret',
'email',
'api_key',
'active',
'level',
'welcomed',
];
/**