73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
|
|
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>
|
|
*/
|
|
protected $policies = [];
|
|
|
|
/**
|
|
* Register any authentication / authorization services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Gate::define('isConceptor', function (User $user) {
|
|
return $user->role === RoleEnum::conceptor;
|
|
});
|
|
|
|
// * POLICIES
|
|
Gate::define(
|
|
'fo.showRe7',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
fn (User|Customer $user) => ($user instanceof User) and !app()->environment(['production']) and
|
|
$user->role->value() <= RoleEnum::marketing->value()
|
|
);
|
|
|
|
Gate::define(
|
|
'fo.showProducts',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
fn (User|Customer|null $user) => View::exists('theme::pages.products') and
|
|
(bool)Product::getCached()->count()
|
|
);
|
|
|
|
Gate::define(
|
|
'fo.showFaq',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
fn (User|Customer|null $user) => View::exists('theme::pages.faq') and
|
|
(bool)FaqQuestion::getCached()->count()
|
|
);
|
|
|
|
Gate::define(
|
|
'fo.gameEnabled',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
function (User|Customer|null $user) {
|
|
/** @var \App\Models\Settings */
|
|
$settings = app(Settings::class);
|
|
return $settings->checkGameCanBePlayed();
|
|
}
|
|
);
|
|
|
|
Auth::provider('crm', function ($app, array $config) {
|
|
return new CrmUserProvider($app['hash'], $config['model']);
|
|
});
|
|
}
|
|
}
|