Skip to content

Commit ae8aa53

Browse files
authored
Merge pull request #2081 from CachetHQ/welcome-users-login
Welcome all users to their status page
2 parents a515f41 + 6685ae9 commit ae8aa53

File tree

13 files changed

+312
-25
lines changed

13 files changed

+312
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Cachet.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace CachetHQ\Cachet\Bus\Commands\User;
13+
14+
use CachetHQ\Cachet\Models\User;
15+
16+
/**
17+
* This is the welcome user command.
18+
*
19+
* @author James Brooks <james@alt-three.com>
20+
*/
21+
final class WelcomeUserCommand
22+
{
23+
/**
24+
* The user.
25+
*
26+
* @var \CachetHQ\Cachet\Models\User
27+
*/
28+
public $user;
29+
30+
/**
31+
* Create a new welcome user command instance.
32+
*
33+
* @param \CachetHQ\Cachet\Models\User $user
34+
*
35+
* @return void
36+
*/
37+
public function __construct(User $user)
38+
{
39+
$this->user = $user;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Cachet.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace CachetHQ\Cachet\Bus\Events\User;
13+
14+
use CachetHQ\Cachet\Models\User;
15+
16+
/**
17+
* This is the user was welcomed event.
18+
*
19+
* @author James Brooks <james@alt-three.com>
20+
*/
21+
final class UserWasWelcomedEvent implements UserEventInterface
22+
{
23+
/**
24+
* The user.
25+
*
26+
* @var \CachetHQ\Cachet\Models\User
27+
*/
28+
public $user;
29+
30+
/**
31+
* Create a new user was welcomed event instance.
32+
*
33+
* @param \CachetHQ\Cachet\Models\User $user
34+
*
35+
* @return void
36+
*/
37+
public function __construct(User $user)
38+
{
39+
$this->user = $user;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Cachet.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace CachetHQ\Cachet\Bus\Handlers\Commands\User;
13+
14+
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
15+
use CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent;
16+
17+
/**
18+
* This is the welcome user command handler.
19+
*
20+
* @author James Brooks <james@alt-three.com>
21+
*/
22+
class WelcomeUserCommandHandler
23+
{
24+
/**
25+
* Handle the welcome user command.
26+
*
27+
* @param \CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand $command
28+
*
29+
* @return void
30+
*/
31+
public function handle(WelcomeUserCommand $command)
32+
{
33+
$command->user->update(['welcomed' => true]);
34+
35+
event(new UserWasWelcomedEvent($command->user));
36+
}
37+
}

app/Foundation/Providers/EventServiceProvider.php

+3
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,8 @@ class EventServiceProvider extends ServiceProvider
138138
'CachetHQ\Cachet\Bus\Events\User\UserWasRemovedEvent' => [
139139
//
140140
],
141+
'CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent' => [
142+
//
143+
],
141144
];
142145
}

app/Http/Controllers/Dashboard/DashboardController.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@
1111

1212
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
1313

14+
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
1415
use CachetHQ\Cachet\Integrations\Contracts\Feed;
1516
use CachetHQ\Cachet\Models\Component;
1617
use CachetHQ\Cachet\Models\ComponentGroup;
1718
use CachetHQ\Cachet\Models\Incident;
1819
use CachetHQ\Cachet\Models\Subscriber;
1920
use Illuminate\Routing\Controller;
21+
use Illuminate\Support\Facades\Auth;
2022
use Illuminate\Support\Facades\Config;
2123
use Illuminate\Support\Facades\Redirect;
2224
use Illuminate\Support\Facades\View;
2325
use Jenssegers\Date\Date;
2426

27+
/**
28+
* This is the dashboard controller class.
29+
*
30+
* @author James Brooks <james@alt-three.com>
31+
*/
2532
class DashboardController extends Controller
2633
{
2734
/**
@@ -83,6 +90,11 @@ public function showDashboard()
8390
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
8491
$ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
8592

93+
$welcomeUser = !Auth::user()->welcomed;
94+
if ($welcomeUser) {
95+
dispatch(new WelcomeUserCommand(Auth::user()));
96+
}
97+
8698
$entries = null;
8799
if ($feed = $this->feed->latest()) {
88100
$entries = array_slice($feed->channel->item, 0, 5);
@@ -95,7 +107,8 @@ public function showDashboard()
95107
->withSubscribers($subscribers)
96108
->withEntries($entries)
97109
->withComponentGroups($componentGroups)
98-
->withUngroupedComponents($ungroupedComponents);
110+
->withUngroupedComponents($ungroupedComponents)
111+
->withWelcomeUser($welcomeUser);
99112
}
100113

101114
/**

app/Http/Controllers/SetupController.php

-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Illuminate\Support\Facades\Redirect;
2323
use Illuminate\Support\Facades\Request;
2424
use Illuminate\Support\Facades\Response;
25-
use Illuminate\Support\Facades\Session;
2625
use Illuminate\Support\Facades\Validator;
2726
use Illuminate\Support\Facades\View;
2827

@@ -217,8 +216,6 @@ public function postStep3()
217216
$this->writeEnv($envKey, $envValue);
218217
}
219218

220-
Session::flash('setup.done', true);
221-
222219
if (Request::ajax()) {
223220
return Response::json(['status' => 1]);
224221
}

app/Models/User.php

+31
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
use Illuminate\Database\Eloquent\ModelNotFoundException;
2222
use Illuminate\Support\Facades\Hash;
2323

24+
/**
25+
* This is the user model.
26+
*
27+
* @author James Brooks <james@alt-three.com>
28+
*/
2429
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
2530
{
2631
use Authenticatable, CanResetPassword, ValidatingTrait;
@@ -39,6 +44,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
3944
*/
4045
const LEVEL_USER = 2;
4146

47+
/**
48+
* The model's attributes.
49+
*
50+
* @var string[]
51+
*/
52+
protected $attributes = [
53+
'welcomed' => false,
54+
];
55+
4256
/**
4357
* The attributes that should be casted to native types.
4458
*
@@ -51,6 +65,23 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
5165
'api_key' => 'string',
5266
'active' => 'bool',
5367
'level' => 'int',
68+
'welcomed' => 'bool',
69+
];
70+
71+
/**
72+
* The fillable properties.
73+
*
74+
* @var string[]
75+
*/
76+
protected $fillable = [
77+
'username',
78+
'password',
79+
'google_2fa_secret',
80+
'email',
81+
'api_key',
82+
'active',
83+
'level',
84+
'welcomed',
5485
];
5586

5687
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Cachet.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Illuminate\Database\Migrations\Migration;
13+
use Illuminate\Database\Schema\Blueprint;
14+
use Illuminate\Support\Facades\Schema;
15+
16+
class AlterTableUsersAddWelcomedColumn extends Migration
17+
{
18+
/**
19+
* Run the migrations.
20+
*
21+
* @return void
22+
*/
23+
public function up()
24+
{
25+
Schema::table('users', function (Blueprint $table) {
26+
$table->boolean('welcomed')->default(false)->after('level');
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*
33+
* @return void
34+
*/
35+
public function down()
36+
{
37+
Schema::table('users', function (Blueprint $table) {
38+
$table->dropColumn('welcomed');
39+
});
40+
}
41+
}

resources/lang/en/dashboard.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
'login' => [
234234
'login' => 'Login',
235235
'logged_in' => 'You\'re logged in.',
236-
'welcome' => 'Welcome Back!',
236+
'welcome' => 'Welcome back!',
237237
'two-factor' => 'Please enter your token.',
238238
],
239239

@@ -259,16 +259,16 @@
259259

260260
// Welcome modal
261261
'welcome' => [
262-
'welcome' => 'Welcome to your new Status page!',
263-
'message' => 'Your status page is almost ready! You might want to configure these extra settings',
264-
'close' => 'Take me straight to my dashboard',
262+
'welcome' => 'Welcome to your new status page, :username!',
263+
'message' => 'You\'re almost ready but you might want to configure these extra settings first...',
264+
'close' => 'I\'m good thanks!',
265265
'steps' => [
266-
'component' => 'Create components',
267-
'incident' => 'Create incidents',
268-
'customize' => 'Customize',
269-
'team' => 'Add users',
270-
'api' => 'Generate API token',
271-
'two-factor' => 'Two Factor Authentication',
266+
'component' => 'Add your components',
267+
'incident' => 'Create an incident',
268+
'customize' => 'Customize your page',
269+
'team' => 'Add your team',
270+
'api' => 'Generate an API token',
271+
'two-factor' => 'Setup Two Factor Authentication',
272272
],
273273
],
274274

resources/views/dashboard/index.blade.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@
8787
@endif
8888
</div>
8989
</div>
90-
@if(Session::get('setup.done'))
90+
@if ($welcome_user)
9191
@include('dashboard.partials.welcome-modal')
92-
<script>
93-
(function() {
94-
$('#welcome-modal').modal('show');
95-
}());
96-
</script>
9792
@endif
9893
@stop

resources/views/dashboard/partials/welcome-modal.blade.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!-- First time welcome Modal -->
21
<div class="modal fade" id="welcome-modal" tabindex="-1" role="dialog">
32
<div class="modal-dialog">
43
<div class="modal-content">
@@ -7,7 +6,7 @@
76
</div>
87
<div class="modal-body">
98
<header>
10-
{{ trans('dashboard.welcome.welcome') }}
9+
{{ trans('dashboard.welcome.welcome', ['username' => $current_user->username]) }}
1110
</header>
1211

1312
<p>
@@ -38,18 +37,18 @@
3837
<div class="row">
3938
<div class="col-md-4 animated fadeInDown">
4039
<a href="{{ route('dashboard.team.add') }}">
41-
<i class="ion ion-ios-people"></i>
40+
<i class="ion ion-ios-people"></i>
4241
{{ trans('dashboard.welcome.steps.team') }}
4342
</a>
4443
</div>
4544
<div class="col-md-4 animated fadeInDown two">
46-
<a href="{{ route('dashboard.user') }}">
45+
<a href="{{ route('dashboard.user.user') }}">
4746
<i class="ion ion-code-working"></i>
4847
{{ trans('dashboard.welcome.steps.api') }}
4948
</a>
5049
</div>
5150
<div class="col-md-4 animated fadeInDown three">
52-
<a href="{{ route('dashboard.user') }}">
51+
<a href="{{ route('dashboard.user.user') }}">
5352
<i class="ion ion-unlocked"></i>
5453
{{ trans('dashboard.welcome.steps.two-factor') }}
5554
</a>
@@ -65,3 +64,9 @@
6564
</div>
6665
</div>
6766
</div>
67+
68+
<script>
69+
(function() {
70+
$('#welcome-modal').modal('show');
71+
}());
72+
</script>

0 commit comments

Comments
 (0)