70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Auth\CrmUserProvider;
|
|
use App\Enums\Users\RoleEnum;
|
|
use App\Models\Customer;
|
|
use App\Models\FaqQuestion;
|
|
use App\Models\Product;
|
|
use App\Models\Settings;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The model to policy mappings for the application.
|
|
*
|
|
* @var array<class-string, class-string>
|
|
*/
|
|
#[\Override]
|
|
protected $policies = [];
|
|
|
|
/**
|
|
* Register any authentication / authorization services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Gate::define('isConceptor', fn (User $user): bool => $user->role === RoleEnum::conceptor);
|
|
|
|
// * POLICIES
|
|
Gate::define(
|
|
'fo.showRe7',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
|
fn (User | Customer $user): bool => $user instanceof User
|
|
&& ! app()->environment(['production'])
|
|
&& $user->role->value() <= RoleEnum::marketing->value()
|
|
);
|
|
|
|
Gate::define(
|
|
'fo.showProducts',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
|
fn (User | Customer | null $user): bool => View::exists('theme::pages.products') && (bool) Product::getCached()->count()
|
|
);
|
|
|
|
Gate::define(
|
|
'fo.showFaq',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
|
fn (User | Customer | null $user): bool => View::exists('theme::pages.faq') && (bool) FaqQuestion::getCached()->count()
|
|
);
|
|
|
|
Gate::define(
|
|
'fo.gameEnabled',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
|
function (User | Customer | null $user) {
|
|
/** @var Settings */
|
|
$settings = resolve(Settings::class);
|
|
|
|
return $settings->checkGameCanBePlayed();
|
|
}
|
|
);
|
|
|
|
Auth::provider('crm', fn ($app, array $config): CrmUserProvider => new CrmUserProvider($app['hash'], $config['model']));
|
|
}
|
|
}
|