ldc-gen-game-web/app/Providers/AuthServiceProvider.php

74 lines
2.3 KiB
PHP
Raw Normal View History

2020-10-21 15:26:21 +02:00
<?php
namespace App\Providers;
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;
use App\Models\Product;
2023-12-12 12:25:45 +01:00
use App\Models\Settings;
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
*/
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-12-05 12:33:25 +01:00
// * POLICIES
2023-12-01 11:45:12 +01:00
Gate::define(
'fo.showRe7',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
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()
);
Gate::define(
'fo.showProducts',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2024-01-31 09:03:18 +00:00
fn (User|Customer|null $user) => View::exists('theme::pages.products') and
2023-11-30 11:10:02 +01:00
(bool)Product::getCached()->count()
);
Gate::define(
'fo.showFaq',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2024-01-31 09:03:18 +00:00
fn (User|Customer|null $user) => View::exists('theme::pages.faq') and
2023-11-30 11:10:02 +01:00
(bool)FaqQuestion::getCached()->count()
);
2023-12-12 12:25:45 +01:00
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();
}
);
2024-01-31 09:03:18 +00:00
Auth::provider('crm', function ($app, array $config) {
return new CrmUserProvider($app['hash'], $config['model']);
});
2020-10-21 15:26:21 +02:00
}
}