2020-10-21 15:26:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2023-11-29 10:57:48 +01:00
|
|
|
use App\Auth\CrmUserProvider;
|
2023-11-23 17:31:28 +01:00
|
|
|
use App\Enums\Users\RoleEnum;
|
2023-11-29 17:00:54 +01:00
|
|
|
use App\Models\Customer;
|
2023-11-30 11:10:02 +01:00
|
|
|
use App\Models\FaqQuestion;
|
2023-11-29 15:33:23 +01:00
|
|
|
use App\Models\Product;
|
2023-11-23 17:31:28 +01:00
|
|
|
use App\Models\User;
|
2020-10-21 15:26:21 +02:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
2024-01-31 09:03:18 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-11-23 17:31:28 +01:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2024-01-31 09:03:18 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2020-10-21 15:26:21 +02:00
|
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
2023-11-23 17:31:28 +01:00
|
|
|
* The model to policy mappings for the application.
|
2020-10-21 15:26:21 +02:00
|
|
|
*
|
2023-11-23 17:31:28 +01:00
|
|
|
* @var array<class-string, class-string>
|
2020-10-21 15:26:21 +02:00
|
|
|
*/
|
2022-01-11 12:39:28 +01:00
|
|
|
protected $policies = [];
|
2020-10-21 15:26:21 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register any authentication / authorization services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2023-11-23 17:31:28 +01:00
|
|
|
public function boot(): void
|
2020-10-21 15:26:21 +02:00
|
|
|
{
|
2023-11-23 17:31:28 +01:00
|
|
|
Gate::define('isConceptor', function (User $user) {
|
|
|
|
|
return $user->role === RoleEnum::conceptor;
|
|
|
|
|
});
|
2023-11-29 10:57:48 +01:00
|
|
|
|
2023-12-05 12:33:25 +01:00
|
|
|
// * POLICIES
|
2023-12-01 11:45:12 +01:00
|
|
|
Gate::define(
|
|
|
|
|
'fo.showRe7',
|
2025-08-14 14:12:13 +00:00
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
2025-04-18 16:59:57 +02:00
|
|
|
fn(User|Customer $user) => ($user instanceof User) and !app()->environment(['production']) and
|
2023-12-01 11:45:12 +01:00
|
|
|
$user->role->value() <= RoleEnum::marketing->value()
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-29 15:33:23 +01:00
|
|
|
Gate::define(
|
|
|
|
|
'fo.showProducts',
|
2025-07-18 16:05:34 +02:00
|
|
|
fn() => View::exists('theme::pages.products') and
|
2025-08-14 14:12:13 +00:00
|
|
|
(bool) Product::getCached()->count()
|
2023-11-30 11:10:02 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Gate::define(
|
|
|
|
|
'fo.showFaq',
|
2025-07-18 16:05:34 +02:00
|
|
|
fn() => View::exists('theme::pages.faq') and
|
2025-08-14 14:12:13 +00:00
|
|
|
(bool) FaqQuestion::getCached()->count()
|
2023-11-29 15:33:23 +01:00
|
|
|
);
|
|
|
|
|
|
2023-12-12 12:25:45 +01:00
|
|
|
Gate::define(
|
|
|
|
|
'fo.gameEnabled',
|
2025-07-25 17:21:23 +02:00
|
|
|
// Keep this, Laravel need user.
|
|
|
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
|
|
|
|
function ($user = null) {
|
2023-12-12 12:25:45 +01:00
|
|
|
/** @var \App\Models\Settings */
|
2025-04-18 16:59:57 +02:00
|
|
|
$settings = \tenant()->setting;
|
2023-12-12 12:25:45 +01:00
|
|
|
return $settings->checkGameCanBePlayed();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-31 09:03:18 +00:00
|
|
|
Auth::provider('crm', function ($app, array $config) {
|
2023-11-29 10:57:48 +01:00
|
|
|
return new CrmUserProvider($app['hash'], $config['model']);
|
|
|
|
|
});
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
}
|