diff --git a/app/Bus/Commands/User/WelcomeUserCommand.php b/app/Bus/Commands/User/WelcomeUserCommand.php new file mode 100644 index 00000000..65f805e5 --- /dev/null +++ b/app/Bus/Commands/User/WelcomeUserCommand.php @@ -0,0 +1,41 @@ + + */ +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; + } +} diff --git a/app/Bus/Events/User/UserWasWelcomedEvent.php b/app/Bus/Events/User/UserWasWelcomedEvent.php new file mode 100644 index 00000000..a2f052d7 --- /dev/null +++ b/app/Bus/Events/User/UserWasWelcomedEvent.php @@ -0,0 +1,41 @@ + + */ +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; + } +} diff --git a/app/Bus/Handlers/Commands/User/WelcomeUserCommandHandler.php b/app/Bus/Handlers/Commands/User/WelcomeUserCommandHandler.php new file mode 100644 index 00000000..d0f1e505 --- /dev/null +++ b/app/Bus/Handlers/Commands/User/WelcomeUserCommandHandler.php @@ -0,0 +1,37 @@ + + */ +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)); + } +} diff --git a/app/Foundation/Providers/EventServiceProvider.php b/app/Foundation/Providers/EventServiceProvider.php index 5575b6b5..b0f970da 100644 --- a/app/Foundation/Providers/EventServiceProvider.php +++ b/app/Foundation/Providers/EventServiceProvider.php @@ -138,5 +138,8 @@ class EventServiceProvider extends ServiceProvider 'CachetHQ\Cachet\Bus\Events\User\UserWasRemovedEvent' => [ // ], + 'CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent' => [ + // + ], ]; } diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index 4e1c9cda..9d2d2c17 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -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 + */ 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); } /** diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 2676d57a..b4f56a93 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -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]); } diff --git a/app/Models/User.php b/app/Models/User.php index c361d0d0..89d88321 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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 + */ 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', ]; /** diff --git a/database/migrations/2016_08_23_114610_AlterTableUsersAddWelcomedColumn.php b/database/migrations/2016_08_23_114610_AlterTableUsersAddWelcomedColumn.php new file mode 100644 index 00000000..2783fa19 --- /dev/null +++ b/database/migrations/2016_08_23_114610_AlterTableUsersAddWelcomedColumn.php @@ -0,0 +1,41 @@ +boolean('welcomed')->default(false)->after('level'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('welcomed'); + }); + } +} diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index 6b78f749..9f6dc062 100644 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -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', ], ], diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 0067debe..ec25a25e 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -87,12 +87,7 @@ @endif -@if(Session::get('setup.done')) +@if ($welcome_user) @include('dashboard.partials.welcome-modal') - @endif @stop diff --git a/resources/views/dashboard/partials/welcome-modal.blade.php b/resources/views/dashboard/partials/welcome-modal.blade.php index f600c245..d452b05e 100644 --- a/resources/views/dashboard/partials/welcome-modal.blade.php +++ b/resources/views/dashboard/partials/welcome-modal.blade.php @@ -1,4 +1,3 @@ -