mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
Merge pull request #2081 from CachetHQ/welcome-users-login
Welcome all users to their status page
This commit is contained in:
commit
ae8aa53bdd
41
app/Bus/Commands/User/WelcomeUserCommand.php
Normal file
41
app/Bus/Commands/User/WelcomeUserCommand.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
41
app/Bus/Events/User/UserWasWelcomedEvent.php
Normal file
41
app/Bus/Events/User/UserWasWelcomedEvent.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
37
app/Bus/Handlers/Commands/User/WelcomeUserCommandHandler.php
Normal file
37
app/Bus/Handlers/Commands/User/WelcomeUserCommandHandler.php
Normal file
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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]);
|
||||
}
|
||||
|
@ -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',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AlterTableUsersAddWelcomedColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('welcomed')->default(false)->after('level');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('welcomed');
|
||||
});
|
||||
}
|
||||
}
|
@ -233,7 +233,7 @@ return [
|
||||
'login' => [
|
||||
'login' => 'Login',
|
||||
'logged_in' => 'You\'re logged in.',
|
||||
'welcome' => 'Welcome Back!',
|
||||
'welcome' => 'Welcome back!',
|
||||
'two-factor' => 'Please enter your token.',
|
||||
],
|
||||
|
||||
@ -259,16 +259,16 @@ return [
|
||||
|
||||
// Welcome modal
|
||||
'welcome' => [
|
||||
'welcome' => 'Welcome to your new Status page!',
|
||||
'message' => 'Your status page is almost ready! You might want to configure these extra settings',
|
||||
'close' => 'Take me straight to my dashboard',
|
||||
'welcome' => 'Welcome to your new status page, :username!',
|
||||
'message' => 'You\'re almost ready but you might want to configure these extra settings first...',
|
||||
'close' => 'I\'m good thanks!',
|
||||
'steps' => [
|
||||
'component' => 'Create components',
|
||||
'incident' => 'Create incidents',
|
||||
'customize' => 'Customize',
|
||||
'team' => 'Add users',
|
||||
'api' => 'Generate API token',
|
||||
'two-factor' => 'Two Factor Authentication',
|
||||
'component' => 'Add your components',
|
||||
'incident' => 'Create an incident',
|
||||
'customize' => 'Customize your page',
|
||||
'team' => 'Add your team',
|
||||
'api' => 'Generate an API token',
|
||||
'two-factor' => 'Setup Two Factor Authentication',
|
||||
],
|
||||
],
|
||||
|
||||
|
@ -87,12 +87,7 @@
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@if(Session::get('setup.done'))
|
||||
@if ($welcome_user)
|
||||
@include('dashboard.partials.welcome-modal')
|
||||
<script>
|
||||
(function() {
|
||||
$('#welcome-modal').modal('show');
|
||||
}());
|
||||
</script>
|
||||
@endif
|
||||
@stop
|
||||
|
@ -1,4 +1,3 @@
|
||||
<!-- First time welcome Modal -->
|
||||
<div class="modal fade" id="welcome-modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
@ -7,7 +6,7 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<header>
|
||||
{{ trans('dashboard.welcome.welcome') }}
|
||||
{{ trans('dashboard.welcome.welcome', ['username' => $current_user->username]) }}
|
||||
</header>
|
||||
|
||||
<p>
|
||||
@ -38,18 +37,18 @@
|
||||
<div class="row">
|
||||
<div class="col-md-4 animated fadeInDown">
|
||||
<a href="{{ route('dashboard.team.add') }}">
|
||||
<i class="ion ion-ios-people"></i>
|
||||
<i class="ion ion-ios-people"></i>
|
||||
{{ trans('dashboard.welcome.steps.team') }}
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-4 animated fadeInDown two">
|
||||
<a href="{{ route('dashboard.user') }}">
|
||||
<a href="{{ route('dashboard.user.user') }}">
|
||||
<i class="ion ion-code-working"></i>
|
||||
{{ trans('dashboard.welcome.steps.api') }}
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-4 animated fadeInDown three">
|
||||
<a href="{{ route('dashboard.user') }}">
|
||||
<a href="{{ route('dashboard.user.user') }}">
|
||||
<i class="ion ion-unlocked"></i>
|
||||
{{ trans('dashboard.welcome.steps.two-factor') }}
|
||||
</a>
|
||||
@ -65,3 +64,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
$('#welcome-modal').modal('show');
|
||||
}());
|
||||
</script>
|
||||
|
47
tests/Bus/Commands/User/WelcomeUserCommandTest.php
Normal file
47
tests/Bus/Commands/User/WelcomeUserCommandTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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\Tests\Cachet\Bus\Commands\User;
|
||||
|
||||
use AltThree\TestBench\CommandTrait;
|
||||
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
|
||||
use CachetHQ\Cachet\Bus\Handlers\Commands\User\WelcomeUserCommandHandler;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use CachetHQ\Tests\Cachet\AbstractTestCase;
|
||||
|
||||
/**
|
||||
* This is the welcome user command test class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class WelcomeUserCommandTest extends AbstractTestCase
|
||||
{
|
||||
use CommandTrait;
|
||||
|
||||
protected function getObjectAndParams()
|
||||
{
|
||||
$params = ['user' => new User()];
|
||||
|
||||
$object = new WelcomeUserCommand($params['user']);
|
||||
|
||||
return compact('params', 'object');
|
||||
}
|
||||
|
||||
protected function objectHasRules()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getHandlerClass()
|
||||
{
|
||||
return WelcomeUserCommandHandler::class;
|
||||
}
|
||||
}
|
36
tests/Bus/Events/User/UserWasWelcomedEventTest.php
Normal file
36
tests/Bus/Events/User/UserWasWelcomedEventTest.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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\Tests\Cachet\Bus\Events\User;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
|
||||
/**
|
||||
* This is the user was welcomed event test class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class UserWasWelcomedEventTest extends AbstractUserEventTestCase
|
||||
{
|
||||
protected function objectHasHandlers()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getObjectAndParams()
|
||||
{
|
||||
$params = ['user' => new User()];
|
||||
$object = new UserWasWelcomedEvent($params['user']);
|
||||
|
||||
return compact('params', 'object');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user