feat(monitoring): add pulse

- Added a new gate called `viewPulse` in the `AuthServiceProvider` class.
- The gate allows only admin users to view the Pulse feature.
This commit is contained in:
Rico van Zelst
2023-12-01 21:49:26 +01:00
parent 6c2deaa953
commit 2374a39c77
12 changed files with 796 additions and 264 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class UserCreateCommand extends Command
{
protected $signature = 'user:create';
protected $description = 'Create a new user from CLI';
public function handle(): void
{
if (config('app.env') === 'production') {
if (!$this->confirm('You are in production mode. Are you sure you want to continue?')) {
return;
}
}
$this->info('Creating a new user...');
$name = $this->ask('Name');
$email = $this->ask('Email');
$password = $this->secret('Password');
$password_confirmation = $this->secret('Confirm password');
$admin = $this->confirm('Is this user an admin?');
$this->info('Name: ' . $name);
$this->info('Email: ' . $email);
$this->info('Password: ' . $password);
$this->info('Password confirmation: ' . $password_confirmation);
$this->info('Admin: ' . $admin);
if ($password !== $password_confirmation) {
$this->error('Passwords do not match!');
return;
}
$user = User::create([
'name' => $name,
'email' => $email,
'password' => bcrypt($password),
'admin' => $admin,
]);
$this->info('User with name ' . $user->name . 'created successfully.');
}
}

View File

@@ -23,6 +23,7 @@ class User extends Authenticatable
'name',
'email',
'password',
'admin',
];
/**

View File

@@ -2,28 +2,19 @@
namespace App\Providers;
// use Illuminate\Support\Facades\Gate;
use App\Models\SummonerEmote;
use App\Policies\SummonerEmotePolicy;
use App\Models\User;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
//
SummonerEmote::class => SummonerEmotePolicy::class,
];
/**
* Register any authentication / authorization services.
*/
public function boot(): void
{
//
Gate::define('viewPulse', function (User $user) {
return $user->admin;
});
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\View\Components\Home;
namespace App\View\Components\home;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;