2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Models\Accessory;
|
2017-01-11 14:50:26 -08:00
|
|
|
use Carbon\Carbon;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\Consumable;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Policies\AccessoryPolicy;
|
|
|
|
use App\Policies\AssetPolicy;
|
|
|
|
use App\Policies\ComponentPolicy;
|
|
|
|
use App\Policies\ConsumablePolicy;
|
|
|
|
use App\Policies\LicensePolicy;
|
|
|
|
use App\Policies\UserPolicy;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
2016-12-19 11:04:28 -08:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
use Laravel\Passport\Passport;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The policy mappings for the application.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $policies = [
|
2016-12-19 11:04:28 -08:00
|
|
|
Asset::class => AssetPolicy::class,
|
|
|
|
Accessory::class => AccessoryPolicy::class,
|
|
|
|
Component::class => ComponentPolicy::class,
|
|
|
|
Consumable::class => ConsumablePolicy::class,
|
|
|
|
License::class => LicensePolicy::class,
|
|
|
|
User::class => UserPolicy::class,
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2016-12-14 04:32:24 -08:00
|
|
|
* Register any authentication / authorization services.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-14 04:32:24 -08:00
|
|
|
public function boot()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2017-04-27 07:09:46 -07:00
|
|
|
|
|
|
|
$this->commands([
|
|
|
|
\Laravel\Passport\Console\InstallCommand::class,
|
|
|
|
\Laravel\Passport\Console\ClientCommand::class,
|
|
|
|
\Laravel\Passport\Console\KeysCommand::class,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
2016-12-14 10:06:05 -08:00
|
|
|
$this->registerPolicies();
|
|
|
|
Passport::routes();
|
2017-01-11 14:50:26 -08:00
|
|
|
Passport::tokensExpireIn(Carbon::now()->addYears(20));
|
|
|
|
Passport::refreshTokensExpireIn(Carbon::now()->addYears(20));
|
2017-01-11 03:38:55 -08:00
|
|
|
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
// --------------------------------
|
|
|
|
// BEFORE ANYTHING ELSE
|
|
|
|
// --------------------------------
|
2017-01-11 14:50:26 -08:00
|
|
|
// If this condition is true, ANYTHING else below will be assumed
|
2016-06-02 02:40:49 -07:00
|
|
|
// to be true. This can cause weird blade behavior.
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::before(function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if ($user->isSuperUser()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// GENERAL GATES
|
|
|
|
// These control general sections of the admin
|
|
|
|
// --------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('admin', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if ($user->hasAccess('admin')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Reports
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('reports.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if ($user->hasAccess('reports.view')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-31 16:52:25 -07:00
|
|
|
# -----------------------------------------
|
|
|
|
# Self
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('self.two_factor', function ($user) {
|
2016-10-31 16:52:25 -07:00
|
|
|
if (($user->hasAccess('self.two_factor')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|